Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
ENERGEN
Published

Gas Leakage Detector

How to use MQ2 Gas Sensor

BeginnerProtip2,851
Gas Leakage Detector

Things used in this project

Hardware components

Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring

Connect all Grounds to Arduino GND pin.

Code

Project Code

Arduino
int red_led=13;//indicates gas
int green_led=12;//indicates normal
int smokeA0 = A0;//indicates sensor is connected to A5
int sensorThres=400;//The threshold value

void setup()
{
pinMode(red_led,OUTPUT);//red led as output
pinMode(green_led,OUTPUT);//green led as output
pinMode(A0,INPUT);//sensor as input
Serial.begin(9600);//starts the code
}
void loop()//loops
{
int gas_avalue=analogRead(smokeA0);//reads sensor value
if (gas_avalue > sensorThres)//sees if it reached threshold value
{
digitalWrite(red_led, HIGH);//turns on red led
digitalWrite(green_led, LOW);//turns off green led

}
else//if it hasn't reached threshold value
{
digitalWrite(red_led, LOW);//turns red led off
digitalWrite(green_led, HIGH);//turn green led on

}
delay(100);//delay 0.1 sec
}

Credits

ENERGEN

ENERGEN

17 projects • 10 followers
Youtube creator

Comments