Interfacing Gas Sensor (MQ2) with Raspberry Pi 3 ๐ฅ
๐ฏ Objective
To detect gases like LPG, smoke, or methane using the MQ2 Gas Sensor and Raspberry Pi 3. Helpful for creating safety and fire alert systems.
๐งฐ Components Required
Component | Quantity |
Raspberry Pi 3 | 1 |
MQ2 Gas Sensor Module (with digital output) | 1 |
Jumper Wires | As required |
Breadboard | 1 |
⚡ Circuit Connections
MQ2 Sensor Pin | Connect To |
VCC | 5V (Raspberry Pi) |
GND | GND (Raspberry Pi) |
D0 | GPIO27 (Pin 13) |
๐ง Python Code
import RPi.GPIO as GPIO
import time
GAS_SENSOR_PIN = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(GAS_SENSOR_PIN, GPIO.IN)
try:
while True:
if GPIO.input(GAS_SENSOR_PIN) == 0:
print("๐ฅ Gas Detected!")
else:
print("✅ Air is Clean.")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
๐ Output
- Displays "๐ฅ Gas Detected!" when smoke or gas is present.
- Shows "✅ Air is Clean." when the environment is safe.
๐ก Applications
- Home safety systems
- Industrial gas detection
- Smart kitchen alerts
๐ฏ เคเคฆ्เคฆिเคท्เค
MQ2 เคธेเคจ्เคธเคฐ เคตाเคชเคฐूเคจ เคงूเคฐ, เคเคฒเคชीเคी, เคिंเคตा เคฎिเคฅेเคจเคธाเคฐเค्เคฏा เคॅเคธเคे เคจिเคฆाเคจ เคเคฐเคฃे เคเคฃि เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ 3 เคตเคฐ เค
เคฒเคฐ्เค เคฆเคฐ्เคถเคตเคฃे.
๐งฐ เคฒाเคเคฃाเคฐे เคธाเคนिเคค्เคฏ
เคเคเค | เคธंเค्เคฏा |
Raspberry Pi 3 | 1 |
MQ2 Gas Sensor Module | 1 |
เคंเคชเคฐ เคตाเคฏเคฐ्เคธ | เคเคฐเคेเคจुเคธाเคฐ |
เคฌ्เคฐेเคกเคฌोเคฐ्เคก | 1 |
⚡ เคธเคฐ्เคिเค เคเคจेเค्เคถเคจ
MQ2 Sensor | เคोเคกเคฃी |
VCC | 5V (Raspberry Pi) |
GND | GND (Raspberry Pi) |
D0 | GPIO27 (Pin 13) |
๐ง เคชाเคเคฅเคจ เคोเคก
import RPi.GPIO as GPIO
import time
GAS_SENSOR_PIN = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(GAS_SENSOR_PIN, GPIO.IN)
try:
while True:
if GPIO.input(GAS_SENSOR_PIN) == 0:
print("๐ฅ เคॅเคธ เคเคขเคณเคฒा เคเคนे!")
else:
print("✅ เคนเคตा เคธ्เคตเค्เค เคเคนे.")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
๐ เคเคเคเคชुเค
- "๐ฅ เคॅเคธ เคเคขเคณเคฒा เคเคนे!" เคนे เคเคจ्เคธोเคฒเคตเคฐ เคช्เคฐिंเค เคนोเคคे.
- "✅ เคนเคตा เคธ्เคตเค्เค เคเคนे." เค
เคธेเคนी เคช्เคฐिंเค เคนोเคคे.
๐ก เคเคชเคฏोเค
- เคเคฐाเคธाเค ी เค
เค्เคจिเคธुเคฐเค्เคทा เคช्เคฐเคฃाเคฒी
- เคเคฆ्เคฏोเคांเคธाเค ी เคॅเคธ เคกिเคेเค्เคถเคจ
- เคธ्เคตเคฏंเคชाเคเคเคฐाเคคीเคฒ เคธ्เคฎाเคฐ्เค เค
เคฒเคฐ्เค
Comments