Things used in this project

Hardware components:
A000066 iso both
Arduino Arduino UNO & Genuino UNO
×1
SeeedStudio GPRS Shield V2.0
×1
Power Supply 12V@2A
×1
Ultrasonic Range Finder HC-SR04
×1
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×1

Schematics

Circuit
Basic connection circuit
Circuit

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;
  }

}

Credits

Me
Hugo Gomes

http://www.hugogome.net

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Arduino Like Function on Kinetis K82 Freedom Stupid Board
Intermediate
  • 76
  • 4

Protip

1000 of K82 Freedom Boards are collecting dust because of the hobbyist unfriendly IDE, pump up the duds with easy Arduino-like functions.

Arduinomated Car Parking with Voice Assistance in Smartphone
Intermediate
  • 593
  • 11

Full instructions

Make an assistant which tells you about how much to drive backwards without any collision through your smartphone by Arduino and 1Sheeld.

Temperature and humidity meter (iot)
Intermediate
  • 11
  • 1

Measuring temperature and humidity with Arduino and uploading it to the server

Sigfox Forest Fire Detector
Intermediate
  • 2,933
  • 16

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector.

Magic VR Hat
Intermediate
  • 741
  • 8

Wear the hat, get transported to different 360 VR experience.

Remote Lamp
Intermediate
  • 405
  • 4

Full instructions

How to make a lamp controlled by TV remote control.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog