![]() |
VOOZH | about |
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards can read digital & analog inputs from the sensors and The MQ2 smoke sensor is sensitive to smoke gases like LPG, Butane, Propane, Methane, Alcohol, Hydrogen.
In this article, We will learn how can we make a Smoke Detector Alarm using Arduino. When the MQ2 Gas Sensor will detect the smoke level high, the red led will glow and the buzzer will start.
In this circuit, the MQ2 gas sensor detects the level of smoke in the environment and sends the analog value to the Arduino. which compares the value with the standard value if the value is higher, Arduino sends the signal to the led and the red light will be illuminated and the buzzer will be started. otherwise, green led will be illuminated.
//stored pins in variables
#define gasSensor A0
#define buzzer 0
#define ledGreen 1
#define ledRed 2
#define HIGH 600
void setup() {
//Initialising all pins
pinMode(gasSensor, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
}
void loop() {
//Read data from the sensor
int gas_value = analogRead(gasSensor);
//check data from sensor if there is smoke, if will execute otherwise else will execute
if(gas_value > HIGH)
{
tone(buzzer,1000,500);
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen,LOW);
}
else
{
noTone(buzzer);
digitalWrite(ledGreen,HIGH);
digitalWrite(ledRed, LOW);
}
delay(200);
}
Simulator :