making an SMS security system using Arduino 📲

Motion sensors can detect when something is moving in front of them. The most common type of motion sensors is the passive infrared (PIR) sensor, which can be used to detect the presence of people, animals, or other objects that emit heat.


In this tutorial, we will use the PIR sensor with Arduino and the SIM900 GSM shield to send a message to your phone that alerts you when someone enters your house!


Overview


The security system that we will make in this tutorial is a complete wireless security solution that includes a PIR sensor, GSM module and a buzzer. The PIR sensor detects motion and sends an alert through a text message to your mobile phone using the SIM900 GSM module.


Let’s find out more together!


Getting the items


For this project you will need the following components you can buy them from our store.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat SIM900 GSM Shield for Arduino
79 QAR
Sale Off
Voltaat PIR Motion Sensor
17 QAR

Make sure you also have a breadboard and jumper wires to connect everything together

Sale Off
Voltaat Half-size Breadboard
15 QAR
Sale Off
Voltaat Jumper Wires - Male to Male (40 Pack)
10 QAR
Sale Off
Voltaat Active Buzzer - 5V
2 QAR

Wiring it up


Before you begin wiring the shield with your Arduino, let's learn about the SIM900 GSM shield and setup it so that it works properly with you. The following image shows the most important components of the SIM900 GSM shield. Understanding the different parts of the shield will let you understand this tutorial much better.

You will also need a 5V/2A DC adapter to supply the shield with the necessary power through the DC jack. You must check the specifications of the adapter well.


Also, remember to insert the SIM card into the SIM card slot at the bottom of the shield and turn off the PIN lock before you start connecting it to the Arduino.


The shield has a power supply selection switch, which you must turn on when you use the adaptor. To startup the module, you must also push the power key in the side or 2 or 3 sec so it can connect to the network.



LED Status Indicators:

The SIM900 GSM/GPRS shield has three LEDs that show connectivity and power status. You may obtain visual feedback on what's going on with the shield by observing these LEDs.


PWR (power LED):  This LED indicates that the shield is receiving power.


Status: This LED indicates SIM900’s working status. If this LED is on, the chip is in working mode.


Netlight: This LED indicates the status of your cellular network. It’ll blink at various rates to show what state it’s in.


Netlight status: 

off: The SIM900 chip is not running.

64ms on, 800ms off: The SIM900 chip is running but not registered to the cellular network yet.

64ms on, 3 seconds off: The SIM900 chip is registered to the cellular network & can send/receive voice and SMS.

64ms on, 300ms off: The GPRS data connection you requested is active.



To obtain the correct readings from the sensor and control the SIM900 GSM module to send the SMS alert, follow the instructions below that demonstrates how to connect the sensor to the Arduino.


You must make sure the jumper cap is connected as shown in the picture on the serial port select.


Connections from the Arduino to the breadboard:

• Arduino GND pin → Breadboard ground line

• Arduino 5V pin → Breadboard 5V line


Connections from the sim900 GSM module:

• Two GND pin→ Breadboard ground line

• TXD pin → Arduino pin 7

• RXD pin → Arduino pin 8


Connections from the PIR sensor:

• positive pin→ Breadboard 5V line

• Signal pin → Arduino pin 2

• Negative pin → Breadboard ground line


Connections from the buzzer:

• Negative pin→ Breadboard ground line

• Positive pin→ Arduino pin 11


Coding


The code function is to get the reading from the PIR sensor through the Arduino digital pin input and then determine if it is high, which means there is someone in your house.


Then the Arduino will send a message to the phone number that you specified in the code using the SIM900 GSM shield, and the buzzer will be activated. This way, you will be alerted when someone comes to your home.


In order to set up the communication between the Arduino and the SIM900 GSM module, we will use the SoftwareSerial Library. It allows serial communication on other digital pins of an Arduino board.


Let's look at the code, and then you should be able to understand it once you follow the instructions and read the comments.



/*
Voltaat learn (http://learn.voltaat.com/)
Link for full tutorial: https://bit.ly/3DW3oFh

Tutorial: making an SMS security system using Arduino


The code function is to get the reading from the PIR sensor through
the Arduino digital pin input and then determine if it is high,
which means there is someone in your house.

Connections from the Arduino to the breadboard:
• Arduino GND pin → Breadboard ground line
• Arduino 5V pin → Breadboard 5V line

Connections from the sim900 GSM module:
• TWO GND pin→ Breadboard ground line
• TXD pin → Arduino pin 7
• RXD pin → Arduino pin 8

Connections from the PIR sensor:
• positive pin→ Breadboard 5V line
• Signal pin → Arduino pin 2
• Negative pin → Breadboard ground line

Connections from the buzzer:
• Negative pin→ Breadboard ground line
• Positive pin→ Arduino pin 11
*/


//Allows serial communication on other digital pins of an Arduino board
#include < SoftwareSerial.h >

//Configure software serial port with digital pins 7,8
SoftwareSerialSIM900(7,8);

//Define the variable pirSensor to digital Pin 2
int pirSensor =2;

//Define the variable pirSensorRead and initialize its value to 0
int pirSensorRead =0;

//Define the variable buzzer to digital Pin 11
int buzzer =11;

//Commands inside void setup run once.
void setup(){

//Arduino communicates with SIM900 GSM shield at a baud rate of 9600 (9600 bits per second)
SIM900.begin(9600);

Serial.begin(9600);
//buzzer is defined as an output
pinMode(buzzer,OUTPUT);

//pirSensor is defined as an input
pinMode(pirSensor,INPUT);

sendSMS();
}

// Commands inside void loop run forever
void loop()
{
// Read the value of digital output from rainSensor and assign it in the variable pirSensorRead
pirSensorRead =digitalRead(pirSensor);


if(pirSensorRead ==HIGH)
{
//Generates a square wave of the specified frequency (1000)
//on a pin (buzzer)for a duration of 200 Millisecond to make a tone
tone(buzzer,1000,2000);
Serial.println("Security Alarm, There is someone in your house!");
//Function we made to send the SMS
sendSMS();
//Delay for 15 seconds
delay(15000);
}

}

void sendSMS()
{
//Command to set SIM900 GSM to SMS mode
SIM900.print("AT+CMGF=1\r");
//Delay for 100 milliseconds
delay(100);
//Replace +xxxxxxxxxxxxxx with your phone number in international format
SIM900.println("AT+CMGS=\"+xxxxxxxxxxxxxx\"");
delay(100);
//Send "Security Alarm, There is someone in your house!" message
SIM900.println("Security Alarm, There is someone in your house!");
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}

Testing it out




Now you must have correctly wired the SIM900 GSM module and the PIR sensor to the Arduino, as we explained in the wiring section, as well as uploaded the code to your Arduino board.


To test the PIR sensor, try to move in front of it, the sensor will be triggered and the buzzer will sound an alert. You will also receive an SMS on your phone number alerting you that there is someone in your house.


Do you think there are additional features that can be added to this project?


Resources 


Arduino Code

Related Tutorials


In this tutorial, we will use the PIR sensor to send a message to your computer when someone enters your house.

In this tutorial, we will learn how to use a buzzer to make an alarm tone that works every minute as a clock alarm.


In this tutorial, we will use the Arduino to control the servo motor shaft to sweep back and forth across 180 degrees. Let's have a look at it.