#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4);
int sensor1=7;
int sensor2=8;
int sensor3=9;
int speaker1=11;
int speaker1=12;
int Fire_Status;
int sms_count=0;
void setup()
{
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(sensor3,INPUT);
pinMode(speaker1,OUTPUT);
pinMode(speaker2,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
delay(500);
}
void loop()
{
CheckFire();
CheckShutDown();
}
void CheckFire()
{
if(sensor1==LOW)
{
SetAlert(); // Function to Alerts security
}}
if(sensor1==LOW && sensor2==LOW )
{
gateOpen();// Function to send SMS
}
void SetAlert()
{
digitalWrite(speaker1,HIGH);
}
void gateOpen()
{
digitalWrite(speaker2,HIGH);
while(sms_count<3) //Number of SMS Alerts to be sent
{
SendTextMessage(); // Function to send AT Commands to GSM module
}
Fire_Status =1;
}
void CheckShutDown()
{
if(Fire_Status ==1)
{
if(sensor1==HIGH)
{
digitalWrite(speaker,LOW);
sms_count=0;
Fire_Status=0;
}}}
void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //To send SMS in Text Mode
delay(1000);
mySerial.println("AT+CMGS="+919650999749"\r"); // change to the phone number you using
delay(1000);
mySerial.println("FIRE IN KPS ”); //the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(1000);
mySerial.println("AT+CMGS="+919650999749"\r"); // change to the phone number you using
delay(1000);
mySerial.println("Gas Leaking!");//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(1000);
sms_count++;
}