0% found this document useful (0 votes)
64 views5 pages

Gas and Smoke Sensor Code

The document contains 5 sections describing different Arduino projects that use sensors to detect smoke, gas, fire or motion and trigger alerts or notifications. Section 1 describes a smoke and gas sensor that uses LEDs to indicate detection. Section 2 describes a fire and gas sensor that uses LEDs and a buzzer for alerts. Section 3 adds GSM to send SMS alerts. Section 4 uses a PIR sensor to trigger an LED or buzzer on motion detection. Section 5 is a fire alarm that uses a temperature sensor, LCD, and GSM to send SMS alerts and indicate the fire status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views5 pages

Gas and Smoke Sensor Code

The document contains 5 sections describing different Arduino projects that use sensors to detect smoke, gas, fire or motion and trigger alerts or notifications. Section 1 describes a smoke and gas sensor that uses LEDs to indicate detection. Section 2 describes a fire and gas sensor that uses LEDs and a buzzer for alerts. Section 3 adds GSM to send SMS alerts. Section 4 uses a PIR sensor to trigger an LED or buzzer on motion detection. Section 5 is a fire alarm that uses a temperature sensor, LCD, and GSM to send SMS alerts and indicate the fire status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Smoke and Gas 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);
}

2.Fire and Gas detection sensor with buzzer(alarm)

#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.print("Pin A0: ");


Serial.println(analogSensor);
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);

Serial.println("Flame Sensor");

int sensorValue = analogRead(sensorPin);

Serial.println(sensorValue);

if (sensorValue < 100)

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);

3.Smoke/Gas Sensor with GSM module

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);

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);

Serial.print("Gas Level: ");


Serial.println(data);
lcd.print ("Gas Scan is ON");
lcd.setCursor(0,1);
lcd.print("Gas Level: ");
lcd.print(data);
delay(1000);

if ( data > 500) //


{
SendMessage();
Serial.print("Gas detect alarm");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gas Level Exceed");
lcd.setCursor(0,1);
lcd.print("SMS Sent");
delay(1000);

}
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
}
}

5.GSM based fire alarm using ARDUINO


#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial mySerial(9, 10);

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++;
}

You might also like