This article provides a step-by-step guide to building a security alarm system using an Arduino Uno, PIR sensor, SIM800L GSM module, and a buzzer, which detects motion and alerts you of intrusions via a GSM call.
Components Needed
- Arduino Uno
- PIR Sensor
- GSM sim800l Module
- Buzzer
- Wire
- Zero PCB
- 9V power supply
Arduino Uno
- The Arduino Uno has used an ATmega328P microcontroller chip.
- The ATmega328P operates at a clock speed of 16 MHz.
- Flash memory 32KB.
- SRAM of 2KB.
- 1KB of EEPROM.
- The Uno is significantly smaller compared to other Arduino boards.
- The Arduino Uno provides a total of 14 digital I/O pins.
- 6 PIN used for PWM (Pulse Width Modulation) output.
- 6 PIN analog input pins.
- 10-bit resolution.
PIR Sensor
A PIR (Passive Infrared) sensor is a motion sensor widely used in security and automation systems. It contains a pyroelectric sensor, which detects infrared radiation, and a lens to focus the radiation onto the sensor. The crystalline material in the pyroelectric sensor generates an electrical charge when it senses infrared radiation.
GSM sim800l Module
- GSM SIM800L is a popular module that enables communication over GSM (Global System for Mobile Communications) networks. It provides functionalities for making calls, sending and receiving SMS messages, and connecting to the internet.
- The GSM SIM800L module is designed to work with GSM networks, allowing devices to establish communication through cellular networks. It operates on various frequencies and supports 2G, and 3G connectivity, making it compatible with most GSM networks worldwide.
- The module requires a power supply of around 3.7 to 4.2 volts.
Circuit Diagram
PIR Sensor
- The VCC pin of the PIR sensor to the 5V pin on the Arduino Uno.
- The GND (ground) pin of the PIR sensor to the GND pin on the Arduino Uno.
- The OUT pin of the PIR sensor to any digital input pin (6) on the Arduino Uno.
GSM Module
- The positive (VCC) and negative (GND) pins of the SIM800L GSM module to the 3.7 and GND pins on the LM2596 Step down converter, respectively.
- The TX (transmit) pin of the SIM800L GSM module to the RX (receive) pin (2) on the Arduino Uno.
- The RX (receive) pin of the SIM800L GSM module to the TX (transmit) pin (3) on the Arduino Uno.
Source Code
//Prateek
//https://justdoelectronics.com
//https://www.youtube.com/c/JustDoElectronics/videos
#include <SoftwareSerial.h>
const String PHONE = “+918830584864xx”;
#define rxPin 2
#define txPin 3
SoftwareSerial sim800(rxPin, txPin);
int pir_sensor = 6;
void setup() {
pinMode(pir_sensor, INPUT);
Serial.begin(115200);
sim800.begin(9600);
Serial.println(“SIM800L software serial initialize”);
sim800.println(“AT”);
delay(1000);
}
void loop() {
while (sim800.available()) {
Serial.println(sim800.readString());
}
while (Serial.available()) {
sim800.println(Serial.readString());
}
int val = digitalRead(pir_sensor);
if (val == HIGH) {
Serial.println(“Motion detected!”);
Serial.println(“calling….”);
delay(1000);
sim800.println(“ATD” + PHONE + “;”);
delay(20000);
}
}
Let’s go through the code and explain its functionality.
- Includes the required libraries and defines the necessary variables.
- Replace +918830584864xx with the desired phone number.
#include <SoftwareSerial.h>
const String PHONE = “+918830584864xx”;
#define rxPin 2
#define txPin 3
SoftwareSerial sim800(rxPin, txPin);
int pir_sensor = 6;
- The setup() the function is called once at the start of the program.
- It sets the pir_sensor pin as an input.
void setup() {
pinMode(pir_sensor, INPUT);
Serial.begin(115200);
sim800.begin(9600);
Serial.println(“SIM800L software serial initialize”);
sim800.println(“AT”);
delay(1000);
}
- The loop() the function runs continuously after the setup() function.
- It first checks if there is any data available from the GSM module. If so, it reads and prints it on the serial monitor.
void loop() {
while (sim800.available()) {
Serial.println(sim800.readString());
}
while (Serial.available()) {
sim800.println(Serial.readString());
}
int val = digitalRead(pir_sensor);
if (val == HIGH) {
Serial.println(“Motion detected!”);
Serial.println(“calling….”);
delay(1000);
sim800.println(“ATD” + PHONE + “;”);
delay(20000);
}
}
Project Demo
- Set up the PIR sensor pin as an input and the buzzer pin as an output.
- If the motion is detected, trigger the alarm by sounding the buzzer and Call an alert using the GSM module.
Conclusion
This DIY project can be used for the security system of your home and office. if you used the Pir sensor then be care full is detect some time fault signal. I suggest you if you try to make a motion-based security system you used an ultrasonic sensor.