smoke detection alarm using Arduino

In this project we will learn how to work a smoke detection alarm using Arduino. It is one of the best safety equipment for homes, offices or industries. But you can create your own smoke detector alarm system using Arduino. It is suitable for detecting NH3 (ammonia), nitrogen oxide, sulfide, alcohol, benzene, smoke, carbon dioxide, etc. If you want to do more advanced projects like precise gas measurement etc, you need to calibrate them first. In this project, we detect smoke and also calculate the proportion of smoke, which will appear on the LCD screen.

Diagram Circuit Smoke Detector Alarm System:

Smoke detector alarm system code:

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);

int redLED = 2;
int greenLED = 3;
int buzzer = 9;
int sensor = A0;
float smokePercentage;
float remainingGas;
float tolerance = 20;

int base_value = 305; // base value
int state; // state for blinking LED & buzzer without delay function

unsigned long previousMillis = 0;
const long interval = 400; // interval at which to LED blink & Buzzer sound (milliseconds)

void setup() {
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
lcd.begin();
}

void loop() {
unsigned long currentMillis = millis();
float MQ135SensorValues = analogRead(sensor);

Serial.print("Sensor Values: ");
Serial.println(MQ135SensorValues);
lcd.setCursor(0, 0);
lcd.print("Smoke % :");

remainingGas = 1023 - base_value + tolerance;
smokePercentage = (MQ135SensorValues- base_value) /remainingGas ;
if (smokePercentage > 0){
Serial.print("Smoke percentage: ");
Serial.println(smokePercentage*100);
lcd.setCursor(9, 0);
lcd.print(smokePercentage*100);
lcd.setCursor(14, 0);
lcd.print("%");
}
else {
lcd.setCursor(10, 0);
lcd.print("-SAFE-");
}


if (MQ135SensorValues > (base_value + tolerance)) // Checks if MQ135 Sensor Value greater than base + tolerance value
{
digitalWrite(greenLED, LOW);
lcd.setCursor(0, 1);
lcd.print("Smoke Detected!!");
Serial.println("Smoke Detected!!");
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED & buzzer is off turn it on and vice-versa:
if (state == LOW) {
state = HIGH;
} else {
state = LOW;
}
// Red LED and buzzer go HIGH or LOW
digitalWrite(redLED, state);
digitalWrite(buzzer, state);
}
}
else
{
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(buzzer, LOW);
lcd.setCursor(0, 1);
lcd.print("Sensor Value:");
lcd.setCursor(13, 1);
lcd.print(MQ135SensorValues);

}
delay(500);
lcd.clear();
}

 

 

Post a Comment

Previous Post Next Post