GSM-Based Alarm System

 


The GSM-Based Alarm System is a simple, real-time security solution that combines Arduino microcontroller technology, GSM modules, and Bluetooth Low Energy (BLE) to provide instant SMS alerts and flexible recipient management. This system is designed to ensure security while offering an easy-to-use configuration interface through an Android app.


Key Features

1. Real-Time Motion Detection

  • Detects movement using a Passive Infrared (PIR) sensor and immediately triggers an alert.

2. Customizable SMS Alerts

  • Sends SMS notifications via the GSM module to multiple recipients with customizable messages.

3. Android App Integration

  • Allows users to configure recipient phone numbers directly via a Bluetooth Low Energy (BLE) interface.

4. Dynamic Recipient Management

  • Add or remove recipient numbers in real time using the Android app.

5. Secure BLE Communication

  • Provides a reliable and secure connection for configuring the alarm system remotely.

Technology Stack

Hardware

  • Arduino (e.g., Uno, Nano): Central controller for sensors, GSM, and BLE communication.
  • PIR Motion Sensor: Detects movement and triggers alerts.
  • GSM Module (e.g., SIM900): Sends SMS notifications.
  • BLE Module (e.g., HC-05 or HM-10): Facilitates communication with the Android app.
  • Power Supply: Powers the entire setup.

Software

  • Arduino IDE: Used for writing and uploading the program.
  • Android Studio: For building the companion Android app.
  • SQLite (Android): Stores recipient numbers locally in the app.

System Architecture

1. Motion Detection

  • The PIR sensor detects motion and sends a signal to the Arduino.

2. Recipient Configuration

  • The Android app communicates with the BLE module to send updated recipient numbers.
  • The Arduino stores these numbers in memory for SMS alerts.

3. SMS Notification

  • The GSM module sends SMS alerts to the configured recipients when motion is detected.

Sample Arduino Code

This code is just a snippet, not an actual codes used on this project.
#include <SoftwareSerial.h>
#include <EEPROM.h>

SoftwareSerial gsm(7, 8);  // RX, TX for GSM Module
SoftwareSerial ble(10, 11); // RX, TX for BLE Module
int pirPin = 2;             // PIR sensor connected to pin 2
int pirState = LOW;         // Current state of PIR sensor

char phoneNumbers[5][15];   // Storage for 5 recipient numbers
int currentPhoneIndex = 0;

void setup() {
  pinMode(pirPin, INPUT);
  Serial.begin(9600);
  gsm.begin(9600);
  ble.begin(9600);
  Serial.println("GSM-Based Alarm System with BLE Ready");
  loadPhoneNumbers();
}

void loop() {
  int motionDetected = digitalRead(pirPin);
  if (motionDetected == HIGH && pirState == LOW) {
    Serial.println("Motion detected!");
    for (int i = 0; i < 5; i++) {
      if (strlen(phoneNumbers[i]) > 0) {
        sendSMS(phoneNumbers[i], "Alert: Motion detected!");
      }
    }
    pirState = HIGH;
  } else if (motionDetected == LOW && pirState == HIGH) {
    pirState = LOW;
  }
  if (ble.available()) {
    handleBLEInput(ble.readString());
  }
}

void sendSMS(String number, String message) {
  gsm.println("AT+CMGF=1");
  delay(100);
  gsm.println("AT+CMGS=\"" + number + "\"");
  delay(100);
  gsm.println(message);
  delay(100);
  gsm.write(26);
  delay(1000);
  Serial.println("SMS Sent to: " + number);
}

void handleBLEInput(String data) {
  if (data.startsWith("ADD:")) {
    String newNumber = data.substring(4);
    addPhoneNumber(newNumber);
  } else if (data.startsWith("DEL:")) {
    int index = data.substring(4).toInt();
    removePhoneNumber(index);
  }
}

void addPhoneNumber(String number) {
  if (currentPhoneIndex < 5) {
    strncpy(phoneNumbers[currentPhoneIndex], number.c_str(), 15);
    savePhoneNumber(currentPhoneIndex, number);
    currentPhoneIndex++;
    Serial.println("Number added: " + number);
  } else {
    Serial.println("Phone list full!");
  }
}

void removePhoneNumber(int index) {
  if (index >= 0 && index < 5) {
    memset(phoneNumbers[index], 0, sizeof(phoneNumbers[index]));
    savePhoneNumber(index, "");
    Serial.println("Number removed at index: " + String(index));
  }
}

void loadPhoneNumbers() {
  for (int i = 0; i < 5; i++) {
    EEPROM.get(i * 15, phoneNumbers[i]);
  }
}

void savePhoneNumber(int index, String number) {
  EEPROM.put(index * 15, number.c_str());
}

Android App Features

1. BLE Device Scan

  • Scans and connects to the BLE module on the Arduino board.

2. Recipient Management

  • Allows users to add or delete recipient phone numbers.

3. Test Alert

  • Sends a test message to ensure the configuration works correctly.


Benefits

1. User-Friendly Configuration

  • Makes it easy to update recipient details without accessing the hardware.

2. Scalable and Flexible

  • Supports up to five recipients and expandable for more.

3. Cost-Effective

  • Avoids reliance on internet-based systems, ideal for remote locations.
Previous Post Next Post

نموذج الاتصال