Arduino Projects

GSM Alarm System Using Arduino and a PIR Sensor



Arduino GSM Alarm System– This project is based on the Security system using PIR Sensor, Arduino Uno, and GSM module “SIM900A”. The PIR sensor is used for Intruder detection. Whenever an unauthorized person is detected a message is sent on the desired number. A relay module is also connected with the Arduino Uno which can be used to turn on an Alarm or it can be used to turn on any light as an indication that intruder is detected.

As in this project which is based on the GSM Alarm System, the GSM module is used, so with the help of this project the home or office can be monitored from anywhere around the world. This project “ Arduino GSM alarm system “ can be used throughout the world, so far the GSM network is available.

Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

Mini Pir Sensor:

PIR Sensor:

Sim900A GSM Module:

DC 5V 2A Adaptor

1n4007 diode:

10k Resistor:

2n2222 NPN transistor

12V SPDT Relay:

One-Channel Relay Module:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

PIR sensor Module used in the GSM Alarm System:

PIR SENSOR, PIR stands for the Passive Infrared Sensor, PIR SENSOR is most commonly known as the motion sensor. PIR “passive infrared sensor” This sensor is designed for humans and animals detections. The PIR sensor, like the one you can see in the picture above, can be easily used with Arduino Uno or Mega and other microcontrollers as well.

Pir Sensor Parameters:

  1. detection angle of 120 degrees.
  2. the detection range of 7 m.
  3. Size: 32x24mm
  4. 4.TTL switch signal output high signal output (3.3V), a low signal output (0.4V).
  5. 5 the trigger time is adjustable 0.3 seconds to 10 mins
  6. commonly used in security projects/devices
  7. 7 has a reusable trigger.
  8. 4.5 to the 20V working voltage

Gsm Sim900A/Sim900D Module:

This is the GSM module that I will be using in the GSM Alarm System project, in the market we have different types of GSM modules, the one I will be using today is sim900A, the same code is also tested on sim900D, so if you want you can also use sim900D.

If you are from Pakistan, Bangladesh or India make sure you purchase the unlocked version of the sim900A. This GSM sim900A module the one we will be using in this tutorial, as you can see on the screen has no Onboard voltage regulator, so be careful while applying the voltage. Ideal voltage for this GSM module is 4.7v but you can also connect it with the 5v adaptor.

As the ideal voltage for this gsm module is 4.7v to 5volts, so any voltage above this can damage the gsm module. If you don’t have the regulated 5v adaptor then you can also use an lm317t adjustable voltage regulator. I have a very detailed tutorial on this. Watch the video “Click Here”

As you can see sim900A module have so many pins which are clearly labeled but we will be using only 5 of these pins, the power supply pins, GND, Rxd 5v, and Txd 5v. The GND of the gsm sim900A module will be connected with the Arduino GND, Txd of the gsm sim900A will be connected with the Arduino pin7 and finally, the Rxd of the gsm sim900A module will be connected with the  Arduino pin8.

If you want to study more in depth about the GSM SIM900A?

Circuit Diagram of the GSM Alarm System:

gsm pir

The recommended voltage for the GSM sim900A module is 4.7 volts to 5 volts. The TX and RX pins of the gsm module are connected with the Arduino’s pin number 7 and pin number 8, and the Ground of the GSM module is connected with the Arduino’s Ground. A relay module is connected with pin number 13 of the Arduino, while the PIR sensor is connected with pin number 2 of the Arduino. The VCC and GND of the PIR sensor are connected with the Arduino’s 5 volts and Ground.

Arduino Programming of the GSM Alarm System:

We start by including the softwareserial.h header file. The softwareSerial library is used for creating multiple serial ports. As I always say never use the Arduino’s default serial port for the debugging purposes. Now the question is if we use the Arduino’s default serial port for the debugging purposes then how we will connect the GSM module. well, no worries at all we can create multiple serial ports using the softwareserial library. I created a serial port on pin number 7 and pin number 8 with the name SIM900. Pin number 7 is the RX will Pin number 8 is the TX. If you want you can select any other pins. then I defined three variables of the type String and integer. The variable txtForSMS will be used for storing the complete message. A PIR sensor is connected with pin number 2 and a relay is connected with pin number 13.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // gsm module connected here
String textForSMS;

int pirsensor = 2; // pir sensor is connected with pin2 of the arduino
int relay = 13; // Alarm/light can be connected with this relay

void setup() {

      SIM900.begin(9600); // original 19200. while enter 9600 for sim900A
 Serial.println(" logging time completed!");
pinMode(pirsensor, INPUT); 
pinMode(relay, OUTPUT); 
digitalWrite(relay, LOW); 

  delay(5000); // wait for 5 seconds


void loop() {

     if ( digitalRead(pirsensor) == HIGH) // 
       textForSMS =  "\nIntruder detected";  
       digitalWrite(relay, HIGH); 
  Serial.println("message sent."); 
       if ( digitalRead(pirsensor) == LOW) // 
  digitalWrite(relay, LOW);

void sendSMS(String message)
  SIM900.print("AT+CMGF=1\r");                     // AT command to send SMS message
 SIM900.println("AT + CMGS = \"+923339218213\"");  // recipient's mobile number, in international format
  SIM900.println(message);                         // message to send
  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  delay(100);                                     // give module time to send SMS

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button