GSM Based Home Security System | Arduino

Back to Blog
GSM Based Home Security System | Arduino - GSM Based Home Security System | Arduino - GSM Based Home Security System | Arduino - GSM Based Home Security System | Arduino

GSM Based Home Security System | Arduino

In our blog, we are going to make a GSM based home security system. Security is a big challenge everywhere because thefts ,gas leakage etc. are increasing day by day. This system  is used  to alert us from danger by sending SMS through GSM Modules. This project  uses Arduino UNO, SIM800L GSM Module, MQ2 Gas Sensor (Detects LPG, Butane, Methane, Smoke), PIR sensor and LCD display. Here, gas sensor acts as a gas leakage detector, PIR acts as a motion detector (trespasser detector) and LCD to display the message for our reference.

This project detects either gas leaking or motion detection, it sends SMS through a GSM Module when an alert is triggered.

Let’s see how to setup and code our project.

OBJECTIVES OF THIS PROJECT:

  • Detect Gas Leakage (like LPG, Butane, Methane) such petroleum based gaseous substance that can be detected using MQ3 Sensor. PIR detects the motion, We can connect a manual ON/OFF Power Switch to enable or disable to avoid unnecessary triggers. But we are not going to cover this in our project.
  • Setup an SMS based Alert Mechanism and send 3 SMS (3 alert messages) to 2 specified mobile numbers (that is stored in Arduino Code).
  • Produce a sound alarm upon gas leak ,motion detection and stop the alarm once gas leak is under control (gas presence in atmosphere is under normal range).
  • Display status in an LCD using a 16×2 LCD module.

COMPONENTS REQUIRED:

PIN DESCRIPTION:

GSM Module Pins:

TX:Transmitter pin which is connected to RX of arduino.

RX:Receiver pin which is connected to the TX of arduino.

 

PIR Sensor Pins:

VCC: Power Supply Positive

GND: Ground

OUT: Sensor digital output

 

MQ2 Sensor Pins:

VCC: Power Supply Positive

GND: Ground

DO: Sensor Digital output

AO: Analog Output

 

LIBRARY USED:

The library used here is Softwareserial and Liquidcrystal_I2C for lcd. To know how to use the Liquidcrystal_I2C library check out our tutorial links given below.

SoftwareSerial: https://github.com/PaulStoffregen/SoftwareSerial

LCD I2C Library: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

 

LCD Interfacing Types: Check out different ways of interfacing LCD with Arduino

Circuit Diagram:

GSM_Based_Home_Security_System

PROGRAM:

#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 (place your's) for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial gsm(9, 10);//Arduino's (rx,tx)

int gassensor = 8; //Gas Sensor Pin
int buzzer = 6; //Buzzer Pin
int gasRead, Gas_alert_val, recheckGas; //Variables for gas functions
int Gas_Leak_Status; //Gas leakage status
int sms_count = 0; //Set sms_count to 0 initially.
int pir = 5; //PIR Pin
int pir_Status; //PIR Status

void setup()
{

 pinMode(gassensor, INPUT);
 pinMode(buzzer, OUTPUT);
 pinMode(pir, INPUT);
 Serial.begin(9600);
 lcd.begin();
 gsm.begin(4800); //GSM Baud rate
 delay(500);
 digitalWrite(buzzer, LOW);
}
void loop()
{
 int pirsensor = digitalRead(pir); //Read PIR Motion
 //Tigger SMS Alert when Motion detected
 if (pirsensor == HIGH)
 {
 digitalWrite(buzzer, HIGH);
 delay(1000);
 while (sms_count < 3) //Number of SMS Alerts to be sent
 {
 gsm.println("AT+CMGF=1"); //To send SMS in Text Mode
 delay(1000);
 gsm.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // change to the phone number you using
 delay(1000);
 gsm.println("someone entered!");//the content of the message
 delay(200);
 gsm.println((char)26);//the stopping character
 delay(1000);
 gsm.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // change to the phone number you using
 delay(1000);
 gsm.println("pir alert !");//the content of the message
 delay(200);
 gsm.println((char)26);//the message stopping character
 delay(1000);
 sms_count++; //to break while loop after 3 count
 }
 pir_Status = 1;
 lcd.setCursor(0, 1);
 lcd.print("pir Alert! SMS Sent!");
 Serial.println("pir Alert! SMS Sent!");
 delay(2000);
 lcd.clear();
 }
 else
 {
 digitalWrite(buzzer, LOW);
 delay(1000);
 }
 CheckGas(); //Check Gas Leaked or not
 CheckShutDown(); //Check again if gas leakage stopped
}
void CheckGas()
{

 lcd.setCursor(0, 0);
 lcd.print("Home Security");
 //Serial.println("Gas Scan - ON");
 Gas_alert_val = ScanGasLevel();

 //D0 Pin becomes LOW when gas detected
 if (Gas_alert_val == LOW)
 {
 SetAlert(); // Function to send SMS Alerts
 }
}
int ScanGasLevel()
{
 gasRead = digitalRead(gassensor); // reads the Gas sensor D0 Pin

 return gasRead; // returns temperature value in degree celsius
}

void SetAlert()
{
 digitalWrite(buzzer, HIGH);
 while (sms_count < 3) //Number of SMS Alerts to be sent
 {
 gsm.println("AT+CMGF=1"); //To send SMS in Text Mode
 delay(1000);
 gsm.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // change to the phone number you using
 delay(1000);
 gsm.println("Gas Leaking!");//the content of the message
 delay(200);
 gsm.println((char)26);//the stopping character
 delay(1000);
 gsm.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // change to the phone number you using
 delay(1000);
 gsm.println("Gas Leaking!");//the content of the message
 delay(200);
 gsm.println((char)26);//the message stopping character
 delay(1000);
 sms_count++;
 }
 Gas_Leak_Status = 1;
 lcd.setCursor(0, 1);
 lcd.print("Gas Alert! SMS Sent!");
 Serial.println("Gas Alert! SMS Sent!");
 delay(2000);
 lcd.clear();
}

void CheckShutDown()
{
 if (Gas_Leak_Status == 1)
 {

 recheckGas = ScanGasLevel();
 if (recheckGas == HIGH) //D0 Pin becomes HIGH when No Gas
 {
 lcd.setCursor(0, 1);
 lcd.print("No Gas Leaking");
 Serial.println("No Gas Leaking");
 digitalWrite(buzzer, LOW);
 sms_count = 0; //Reset count for next alert triggers
 Gas_Leak_Status = 0;
 }
 }
}

Share this post

Leave a Reply

Back to Blog