info@iobrain.in
+91 93536 94456

Blog

Standing Out From The Rest

Gsm Intruder Alert

Explanation video:(The module I used is for the video is sim800c but the code and working principle are the same)

(Check this post out to learn the basics of GSM module)

This is a project I did using the sim800 gsm module. When set up in a house, this project uses a PID motion detector to check for suspicious activity and if the alarm is not disabled it will call the homeowner and send an SMS using the gsm module.

The alarm can be disabled by sending the SMS “Disable the alarm” and can be enabled by sending the SMS “Enable the alarm”.(case-sensitive).

The project components are:

SIM800L gsm module

PIR motion sensor

Arduino MEGA(you can use other Arduino boards as well)

ITS TIME TO START THE PROJECT EXPLANATION!

First, The connections:

All devices are powered with 5-volt and ground. The transmitter pin of the gsm module is connected to pin no.11 of Arduino and the receiver pin is connected to pin no.10. These pins will be later declared as receiver and transmitter of Arduino using the software serial library.

The output pin of the motion sensor is connected to pin no.2 of Arduino.

When motion is detected by the sensor it will send a signal to the Arduino and if the alarm is not disabled it will command the gsm module to call the number of the house owner and send an SMS to him.

Now, the code.

#include <Wire.h>

#include<SoftwareSerial.h>//libraries used

SoftwareSerial gsm(11,10);//set serial communication

//GSM TX to pin 11 GSM RX to pin 10

int PIR=2;//pin no. of PIR sensor

bool disabled=false;//variable to check if alarm is disabled or not

String dataIn=””;

String data=””;//variables to store data recieved from GSM module

int onetimealarm=1;//can be used if owner wants the alarm to ring only once(to lower sim expenses)

void setup()//runs only once.used to setup the sensors and the gsm module correctly

{

Serial.begin(9600);

gsm.begin(9600);//baud rates for gsm and serial monitor communication

pinMode(LED_BUILTIN,OUTPUT);//used as indicator to check if alarm is enabled or not

pinMode(PIR,INPUT);//motion sensor

gsm.println(“AT+CMGF=1”);//configure text mode

delay(1000);

gsm.println(“AT+CNMI=1,2,0,0,0”);//enable live messaging

delay(1000);

}

void loop(){

 if(disabled){//on the led if alarm is disabled

 digitalWrite(LED_BUILTIN,HIGH);

 }

 else{//and off it if it is enabled

 digitalWrite(LED_BUILTIN,LOW);

 }

 if(disabled==false && digitalRead(PIR)==1 && onetimealarm==1){

 //if the alarm is not disabled and motion is detected

  gsm.print(“AT+CMGS=\”+91xxxxxxxxxx\”\r”);//replace x with your number

  delay(100);//start messaging

  gsm.print(“Intruder alert:”);

  delay(100);

  gsm.println((char)26);//ASCII of ctrl+z

  delay(1000);//end messaging

  gsm.println(“ATD+91xxxxxxxxxx;”);//call the owner(you)

  delay(2000);

  //onetimealarm=0;/*uncomment this if you want the alarm to ring only once every time it’s enabled*/

  }

 if(gsm.available()){//read data from gsm module, if it is there

 Read();

 if(dataIn.startsWith(“+CMT: \”+91xxxxxxxxxx\””))

 {//if sms is recieved from owner

 Read();//read the next line, The actual message(first line gives only number,date and time)

 if(dataIn.indexOf(“Disable the alarm”) != -1){//if, in the message there are words “Disable the alarm”

  Serial.println(“Alarm Disabled!”);

  disabled=true;}

  else if(dataIn.indexOf(“Enable the alarm”) != -1){

  Serial.println(“Alarm Enabled!”);

  onetimealarm=1;

  disabled=false;

  }

  }

  }

  }

  void Read(){//function to read data

  while(gsm.available()>0){//as long as data exsists

  char dat=gsm.read();//read the data one character at a time

  if(dat==’\n’){//if character is newline(enter key of gsm)

  dataIn=data;//set datain as data

  Serial.println(dataIn);//print data

  data=””;//clear data

  break;//stop reading

  }

  data=data+dat;//add each character to data

  }

  }

the explanation is in the code as comments so the code must be pretty self-explanatory

(pun intended).

just know that if you send a message that even contains “Enable the alarm” like

“Please do not Enable the alarm” it will still enable the alarm because it was contained in the message

In the case of messages like “Enable the alarm to Disable the alarm,” it will always take Disable the alarm as the instruction.

You should probably delete the SMS part of the alarm because it is just a waste of network. There are no details mentioned. Calls are enough. (That’s what I did in the explanation video)

That is all.

the explanation video will be uploaded soon

THANK YOU