PIR Sensor Security Alarm with SMS Alert

Project Overview

This project creates a basic home security system that sends SMS alerts to your phone when motion is detected. The system uses an Arduino Uno, a PIR sensor, and a SIM800L GSM module. It’s ideal for monitoring remote properties, sheds, or workshops without Wi-Fi.

Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $25-35

How It Works

The PIR sensor continuously monitors for motion. When motion is detected, the Arduino activates the GSM module to send a pre-configured SMS to your phone number. The system can also sound a local siren and flash lights as deterrents. An optional keypad or switch can arm/disarm the system.

Materials Needed

  • Arduino Uno (1)
  • HC-SR501 PIR sensor (1)
  • SIM800L GSM module (1)
  • SIM card (with SMS capability, prepaid recommended)
  • Buzzer or siren (optional)
  • LED (for status indication)
  • Resistor (220Ω for LED)
  • Push button (for arming/disarming, optional)
  • Power supply (5V 2A minimum)
  • Jumper wires
  • Project enclosure

Circuit Diagram

Connection Table

Component Pin Arduino Pin
PIR Sensor VCC 5V
PIR Sensor GND GND
PIR Sensor OUT Digital Pin 2
SIM800L VCC 5V (use external power for reliable operation)
SIM800L GND GND
SIM800L TXD Digital Pin 3 (via voltage divider)
SIM800L RXD Digital Pin 2 (via voltage divider)
Buzzer Positive Digital Pin 8
Buzzer Negative GND
Status LED Anode Digital Pin 13 (through 220Ω)
Status LED Cathode GND
Arming Switch One pin Digital Pin 7
Arming Switch Other pin GND

Important: SIM800L Voltage Levels

The SIM800L operates at 3.3V logic, while Arduino uses 5V. Use a voltage divider on the TX line (Arduino to SIM800L) to reduce voltage:

  • Connect 1kΩ resistor from Arduino TX to SIM800L RX
  • Connect 2kΩ resistor from SIM800L RX to GND

Arduino Code

#include <SoftwareSerial.h>

// Pin definitions
const int pirPin = 2;
const int buzzerPin = 8;
const int ledPin = 13;
const int armPin = 7;

// GSM module
SoftwareSerial gsm(3, 2); // RX, TX

// Configuration
const char* phoneNumber = "+1234567890"; // Replace with your number
bool armed = true; // Start armed
bool alarmTriggered = false;
unsigned long alarmStartTime = 0;
const unsigned long alarmDuration = 30000; // Siren on for 30 seconds

void setup() {
  Serial.begin(9600);
  gsm.begin(9600);
  
  pinMode(pirPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(armPin, INPUT_PULLUP);
  
  digitalWrite(buzzerPin, LOW);
  digitalWrite(ledPin, LOW);
  
  Serial.println("Security System Starting...");
  Serial.println("Waiting 60 seconds for PIR warm-up...");
  delay(60000);
  
  // Initialize GSM module
  Serial.println("Initializing GSM...");
  sendATCommand("AT", 1000);
  sendATCommand("AT+CMGF=1", 1000); // Text mode
  sendATCommand("AT+CNMI=2,2,0,0,0", 1000); // New SMS indication
  
  Serial.println("System Ready");
  digitalWrite(ledPin, HIGH); // LED on when armed
}

void sendATCommand(String cmd, int timeout) {
  gsm.println(cmd);
  delay(timeout);
  while (gsm.available()) {
    Serial.write(gsm.read());
  }
}

void sendSMS(String message) {
  Serial.println("Sending SMS...");
  gsm.print("AT+CMGS=\"");
  gsm.print(phoneNumber);
  gsm.println("\"");
  delay(500);
  gsm.print(message);
  delay(500);
  gsm.write(26); // Ctrl+Z to send
  delay(3000);
  Serial.println("SMS sent");
}

void triggerAlarm() {
  if (!alarmTriggered && armed) {
    alarmTriggered = true;
    alarmStartTime = millis();
    
    Serial.println("ALARM TRIGGERED!");
    
    // Send SMS
    sendSMS("ALERT: Motion detected at your property!");
    
    // Sound siren
    digitalWrite(buzzerPin, HIGH);
    
    // Flash LED
    for (int i = 0; i < 10; i++) {
      digitalWrite(ledPin, LOW);
      delay(200);
      digitalWrite(ledPin, HIGH);
      delay(200);
    }
  }
}

void resetAlarm() {
  alarmTriggered = false;
  digitalWrite(buzzerPin, LOW);
  if (armed) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
  Serial.println("Alarm reset");
}

void loop() {
  // Check arming status
  bool newArmed = digitalRead(armPin) == LOW;
  if (newArmed != armed) {
    armed = newArmed;
    if (armed) {
      Serial.println("System ARMED");
      digitalWrite(ledPin, HIGH);
      sendSMS("Security system ARMED");
    } else {
      Serial.println("System DISARMED");
      digitalWrite(ledPin, LOW);
      resetAlarm();
      sendSMS("Security system DISARMED");
    }
    delay(500); // Debounce
  }
  
  // Check motion
  bool motion = digitalRead(pirPin) == HIGH;
  if (motion && armed && !alarmTriggered) {
    triggerAlarm();
  }
  
  // Auto-reset alarm after duration
  if (alarmTriggered && (millis() - alarmStartTime > alarmDuration)) {
    resetAlarm();
  }
  
  delay(100);
}

Testing the System

  1. Test GSM module: Use AT commands to verify network registration and SMS capability.
  2. Test PIR sensor: Check that sensor triggers reliably with the LED indicator.
  3. Full system test: Arm the system, trigger motion, and verify SMS is received and siren sounds.

Installation Steps

  1. Assemble circuit: Build on breadboard and test functionality.
  2. Insert SIM card: Ensure SIM card has SMS capability and sufficient credit.
  3. Upload code: Replace phone number with your number, upload to Arduino.
  4. Test indoors: Verify SMS sending and alarm functionality.
  5. Enclose components: Place Arduino and GSM module in weatherproof enclosure.
  6. Mount PIR sensor: Position sensor to cover the area you want to monitor (doorway, window, room corner).
  7. Power the system: Connect to a reliable power source (5V adapter or battery backup).
  8. Final test: Arm system, walk through monitored area, verify SMS received.

Troubleshooting

  • GSM not connecting: Check antenna connection, SIM card insertion, and network coverage. Use AT+CREG? command to check registration status.
  • No SMS received: Verify phone number format (include country code). Check that SIM has credit for SMS.
  • False triggers: Adjust PIR sensitivity or position sensor away from heat sources. Add a delay after arm to avoid self-triggering.
  • Power issues: SIM800L draws up to 2A during transmission. Use a 2A power supply and add 1000µF capacitor across VCC and GND near the module.

Project Extensions

  • Battery backup: Add a 12V battery and charging circuit for power outage protection.
  • Multiple sensors: Add multiple PIR sensors to cover different areas, with zone identification in SMS.
  • Camera integration: Add an ESP32-CAM to capture images when motion is detected and send via MMS or email.
  • Keypad arming: Add a 4×4 keypad for PIN-code arming/disarming.
  • Remote control: Add a Bluetooth module to arm/disarm from your phone.
  • Logging: Add an SD card module to log intrusion events with timestamps.

Conclusion

This SMS-based security system provides reliable intrusion detection without requiring internet connectivity. It’s ideal for remote locations, workshops, or as a backup to your primary security system.

Leave a Reply

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