Gas and Smoke Sensor Code
Gas and Smoke Sensor Code
int VALOR;
int AVISO = 2;
int VERDE = 3;
void setup() {
pinMode(A0, INPUT);
pinMode(AVISO, OUTPUT);
pinMode(VERDE, OUTPUT);
}
void loop() {
digitalWrite(VERDE, HIGH);
VALOR = analogRead(A0 > 400);
if(VALOR == 400) {
digitalWrite(AVISO, HIGH);
delay(500);
digitalWrite(AVISO, LOW);
delay(500);
}
#include<SoftwareSerial.h>
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A0;
int sensorPin = A1;
int sensorThres = 500;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
pinMode(sensorPin,INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.println("Flame Sensor");
Serial.println(sensorValue);
Serial.println("Fire Detected");
Serial.println("LED on");
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
tone(buzzer,1000,200);
}
else
{
digitalWrite(redLed,LOW);
digitalWrite(greenLed,HIGH);
noTone(buzzer);
}
delay(100);
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#include <SoftwareSerial.h>
int gasValue = A0; // smoke / gas sensor connected with analog pin A1 of the
arduino / mega.
int data = 0;
void setup()
{
randomSeed(analogRead(0));
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
lcd.begin(16,2);
pinMode(gasValue, INPUT);
lcd.print (" Gas Leakage ");
lcd.setCursor(0,1);
lcd.print (" Detector Alarm ");
delay(3000);
lcd.clear();
}
void loop()
{
data = analogRead(gasValue);
}
else
{
Serial.print("Gas Level Low");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gas Level Normal");
delay(1000);
}
lcd.clear();
}
void SendMessage()
{
Serial.println("I am in send");
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+91900xxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Excess Gas Detected. Open Windows");// The SMS text you want to
send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
Working of the Project
When the circuit is powered on after uploading code, the LCD displays the Gas Level
in some analog numbers. It will display the status of whether the gas level is
normal or excessive. When the gas level exceeds it will display SMS Sent status.
4.PIR SENSOR
void setup() {
pinMode(2, INPUT); //Pin 2 as INPUT
pinMode(3, OUTPUT); //PIN 3 as OUTPUT
}
void loop() {
if (digitalRead(2) == HIGH)
{
digitalWrite(3, HIGH); // turn the LED/Buzz ON
delay(100); // wait for 100 msecond
digitalWrite(3, LOW); // turn the LED/Buzz OFF
delay(100); // wait for 100 msecond
}
}
int sensor=A1;
float temp_read,Temp_alert_val,Temp_shut_val;
int sms_count=0,Fire_Set;
void setup()
{
pinMode(sensor,INPUT);
mySerial.begin(9600);
Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
CheckFire();
CheckShutDown();
}
void CheckFire()
{
lcd.setCursor(0,0);
lcd.print("Fire Scan - ON");
Temp_alert_val=CheckTemp();
if(Temp_alert_val>45)
{
SetAlert(); // Function to send SMS Alerts
}
}
float CheckTemp()
{
temp_read=analogRead(sensor); // reads the sensor output (Vout of LM35)
temp_read=temp_read*5; // converts the sensor reading to temperature
temp_read=temp_read/10; // adds the decimal point
return temp_read; // returns temperature value in degree celsius
}
void SetAlert()
{
while(sms_count<3) //Number of SMS Alerts to be sent
{
SendTextMessage(); // Function to send AT Commands to GSM module
}
Fire_Set=1;
lcd.setCursor(0,1);
lcd.print("Fire Alert! SMS Sent!");
}
void CheckShutDown()
{
if(Fire_Set==1)
{
Temp_shut_val=CheckTemp();
if(Temp_shut_val<28)
{
lcd.setCursor(0,1);
lcd.print("Fire Shut! SAFE NOW");
sms_count=0;
Fire_Set=0;
}}}
void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //To send SMS in Text Mode
delay(2000);
mySerial.println("AT+CMGS=\"+919544xxxxxx\"\r"); // change to the phone number
you using
delay(2000);
mySerial.println("Fire in NEW ROOM!");//the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(5000);
mySerial.println("AT+CMGS=\"+919847xxxxxx\"\r"); // change to the phone number
you using
delay(2000);
mySerial.println("Fire in NEW ROOM!");//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(5000);
sms_count++;
}