Project tutorial
GSM Home Alarm V1.0

GSM Home Alarm V1.0

GSM Home Alarm using a Ultrasonic sensor to detect movement and inform the User of intrusion.

  • 31,597 views
  • 13 comments
  • 44 respects

Components and supplies

About this project

For the Christmas Holidays I will travel to my parents house and due to some recent home invasions in the neighborhood I have decided to leave behind a DIY Alarm System with some things that I had lying around.

This project consists in an Arduino Uno with the SeeedStudio GPRS Shield V2.0 connected to an ultrasonic sensor HC-SR04.

The idea is behind this is very simple, when the ultrasonic sensor detects a difference in the distance that is measuring, I will get a call on my handy. I can then place a call back in order to "rearm" the system.

Gathering the Components 

You will need to have:

  • 1x Arduino Uno
  • 1x GPRS Shield (It is also possible to use other GSM shields available in the market) 
  • 1x Ultrasonic Range Finder HC-SR04
  • 1x Power supply 12V@2A (It recommend to use an external power supply capable of providing 2A to avoid problem with the GSM shield)
  • 1x Breadboard
  • Some wires

Connect the Components

Place a SIM card without PIN CODE in the GPRS Shield.

Place the GPRS Shield on top of the Arduino UNO.

Define pins 7 and 8 as the communication pins in the GPRS Shield, by changing the two jumpers to the left side. 

Connect the VCC and GND in the HC-SR04 to the 5V and GND pins in the Arduino.

Connect the Trig and Echo in the HC-SR04 to the pin 3 and pin 4 pins in the Arduino.

Code

I using a SIM900 library. It is available for download here. Once you install the library in the correct Arduino folder you may need to change somethings.

Setting up the communications pins.

The GPRS Shield V2.0 uses pins 7 and 8 on the Arduino. Open the GSM.cpp file of the library with a text editor. Change the #define _GSM_TXPIN_ to 7 and #define _GSM_RXPIN_ to 8.

//De-comment this two lines below if you have the
//second version og GSM GPRS Shield
#define _GSM_TXPIN_ 7
#define _GSM_RXPIN_ 8	

Save the file.

Debug Mode

Open GSM.h file with a text editor. Turn off the Debug Mode in the library in the following code line by commenting it. 

GSM_ON

On the same file, you will need to change the GSM_ON pin to pin 9.

// pins definition
#define GSM_ON              9 // connect GSM Module turn ON to pin 77 
//#define GSM_RESET         9

Comment all the other pin 9 #define statements. 

Save the file.

Download the Arduino code

Get my code from the code section of this project. After downloading replace the "XXXXXXX" in the code by your phone number. 

char user_phone_number[] = "XXXXXXXXXXXXX"; //DEFINE YOUR USER CELLPHONE NUMBER

Compile and Upload.

Note: Make sure that the phone number that you insert is equal to the one displayed in the Serial Monitor when you make a call.

ATTESO: Your_Phone_Number_to_insert_in_the_XXXXXXX    

Open a Serial Monitor window

After upload, open a Serial Monitor window in the Arduino IDE. The program will start to display first the attempting connection with the GPRS shield.

When the Shield is ready, you still can have the message, Waiting for Network Registration . If this appends you will have to wait for a few minutes in order for the Shield connect to the GSM network. The green LED will be fast blinking during this period.

Test it

When the program is running pass your hand in front of the HC-SR04. You should get the message Movement  in the serial monitor and a call on your handy.

Place a call to the your system number and the alarm should "rearm" again.

Pros and Cons

I still have not performed a long test run on the system, but I already notice that sometimes the measurements displayed can present a problem if you are measuring long distances. 

Future updates:

Probably an PIR sensor will get better results for this project then the ultrasonic sensor.

An output circuit (relay or MOSFET) should be also included, this would allow me to connect a siren or to activate any other system remotely.

Please write me if you found any mistake, if you have any suggestion/improvement or questions.

Thanks for reading.

Hugo Gomes

Code

CodeArduino
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "call.h"


//Classes for the gsm libs
CallGSM call;


char phone_number[20];
char user_phone_number[] = "XXXXXXXXXXXXX"; //DEFINE YOUR USER CELLPHONE NUMBER

//Flag to just inform the user one time
boolean user_informed_movement = false;


byte trigPin = 3; //Pin from HC-SR04 "Trig"
byte echoPin = 4; //Pin from HC-SR04 "Echo"




void setup() {


  //Define HC-SR04 pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT); 
  pinMode(GSM_ON, OUTPUT); //Pinmode for Digital Pin 9


  Serial.begin(9600); //Start a Serial COM
  
  Serial.println(F("GSM ALARM V1.0"));
  
  Serial.print(F("Starting GSM COM..."));

  if (gsm.begin(9600)) //Start the GSM COM
  {
    Serial.println(F("ready"));
  }
  else
  {
    Serial.println(F("Could not connect to GSM modem"));
  }


  //Wait for the GSM to register in an network
  while (gsm.CheckRegistration() != 1) {

    Serial.println(F("Waiting for Network Registration"));
    delay(5000);
  }

}



void loop() {

  //First lets see if we have a call to reset the "already informed user"
  if (user_informed_movement==true) check_call();

  //Check for movement
  //If we have movement and the user is still not informed, lets do a call.
  if (movement() && user_informed_movement == false)
  {
    Serial.println(F("Movement"));

    //If there is no active call, we can do a call
    if (call.CallStatus() != CALL_ACTIVE_VOICE) {

      call.Call(user_phone_number);

      delay(15000); //Give some time for the call to take place
      call.HangUp();


      //User is already informed of movement
      user_informed_movement = true;

    }
  }

}


//******************************************************************************//***************************    CHECK CALL    *********************************
//******************************************************************************

void check_call()
{

  //Check call from an any number
  byte stat = call.CallStatusWithAuth(phone_number, 0, 0);


  //A call if being placed
  if (stat == CALL_INCOM_VOICE_AUTH) {
    //Hang up the call.
    call.HangUp();

    delay(1000);

    //Compare the phone number from the call placer to the user number
    if (strcmp(phone_number, user_phone_number) == 0)
    {
      //Reset warning flag
      user_informed_movement = false;
    }
  }

}

//******************************************************************************
//****************************    MOVEMENT    **********************************
//******************************************************************************

byte movement()
{

  long duration, distance;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);

  //Calculate the distance (in cm) based on the speed of sound.
  distance = duration / 58.2;

  Serial.print(F("Dist:"));
  Serial.println(distance);

  delay(50);

  if (distance >= 80 || distance <= 0)  return 0; //Ajust this values according to your needs

  else
  {
    return 1;
  }

}

Schematics

Circuit
Basic connection circuit
Circuit

Comments

Similar projects you might like

Making Capacitance Alarm with Arduino

Project tutorial by muhammed shameel k.v

  • 859 views
  • 0 comments
  • 1 respect

Buzzer Alarm System With Help Of Arduino

by Team ONYX

  • 37,874 views
  • 5 comments
  • 21 respects

Intruder Alarm with Text Message Notification

Project tutorial by Matthew Hallberg

  • 25,587 views
  • 13 comments
  • 50 respects

GSM based Home Automation

Project tutorial by Team Brink.IO

  • 18,635 views
  • 45 comments
  • 38 respects

Entry Level Door Monitoring Alarm System

Project tutorial by Team Robodia Technology Solutions

  • 5,964 views
  • 1 comment
  • 17 respects

Distance Alarm System

Project tutorial by Darwin Dela Cruz

  • 2,973 views
  • 3 comments
  • 14 respects
Add projectSign up / Login