Arduino Motion Detector + Make It Wireless + Call Phone When Motion Detected

27K8746

Intro: Arduino Motion Detector + Make It Wireless + Call Phone When Motion Detected

I have always wanted a motion sensor system at my
house but they are all too expensive.

Since I started working with arduino I realized I could make one myself.

So I made this project in 3 parts :

1) Simple motion sensor with one arduino and a led will flash when motion is detected.

2) Using a second arduino , a transmitter and a receiver I made the system wireless.

3) Using an Arduino GSM shield I will be calling myself every time motion is detected.

In the whole project I will be using WHITE jumper cables for Ground and RED for the 5V.

STEP 1: Parts & Materials

Things that you will need :

1st Part:

  • Arduino Uno
  • LED Indicator
  • Jumper Cables
  • 3 Female to Male Cables
  • Breadboard
  • PIR Motion Sensor
  • 220Ohm Resistor

2nd Part:

All of the above

  • Arduino Uno
  • Breadboard
  • Transmitter and Receiver
  • Power Supply DC 9V/1A For Arduino

3rd Part :

  • Arduino Uno Board
  • GSM shield for Arduino
  • SIM card
  • PIR Motion Sensor
  • Jumper Cables
  • Led Indicator
  • 220 Ohm Resistor
  • 3 Female to Male Cables
  • Breadboard

Let's get started!!!!!

STEP 2: Part 1 : Hardware Setup

Grab some jumper cables and connect the Ground and the 5V to the power buses.

Use the female to male cables to connect your PIR motion sensor to your breadboard.

After that we have to connect them.

First connect the PIR sensor to the power buses as seen in the photo. After that take another cable and connect the OUT of PIR sensor to a Digital Pin of your choice , for my project I will be using Digital Pin 7.

Now its time to connect our LED in the breadboard and via the resistor the the Digital Pin 5 as seen in the photo. I believe i do not need to explain furthermore , but if someone needs help I would gladly help.

That is all the hardware setup that is needed for the 1st part of this Project.

Let's get to the code now...

STEP 3: Part 1 : Coding

---------------------------------------------------------------------

const int sensor_pin = 7;

int prepTime = 30;

long unsigned int lowIn;

long unsigned int pause = 5000;

boolean lockLow = true;

boolean takeLowTime;

int pirPin = 7;

int ledPin = 5;

//SETUP

void setup(){

Serial.begin(9600);

pinMode(pirPin, INPUT);

pinMode(ledPin, OUTPUT);

digitalWrite(pirPin, LOW);

Serial.print("preparing sensor ");

for(int i = 0; i < prepTime; i++){

Serial.print(".");

delay(1000);

}

Serial.println(" done");

Serial.println("SENSOR ACTIVE");

delay(50);

}

//LOOP

void loop(){

if(digitalRead(pirPin) == HIGH){

digitalWrite(ledPin, HIGH);

if(lockLow){

lockLow = false;

Serial.println("---");

Serial.print("motion detected at ");

Serial.print(millis()/1000);

Serial.println(" sec");

delay(50);

}

takeLowTime = true;

}

if(digitalRead(pirPin) == LOW){

digitalWrite(ledPin, LOW);

if(takeLowTime){

lowIn = millis();

takeLowTime = false;

}

if(!lockLow && millis() - lowIn > pause){

lockLow = true;

Serial.print("motion ended at ");

Serial.print((millis() - pause)/1000);

Serial.println(" sec");

delay(50);

}

}

}

---------------------------------------------------------------------

STEP 4: Part 1 : Results

Dropbox link to Video and photos are included so you can see how it should be working.

If you have problems or have any questions dont hesitate to ask.

This is the end of Part 1.

Now let's continue with Part 2 and make the whole thing wireless.

STEP 5: Part 2 : Hardware Setup

Before we start with the setup you will need to download VirtualWire library from the link.

To install the library, just place it in the libraries/ folder of your Arduino folder, for me its C:\Program Files (x86)\Arduino\libraries.

So let's start connecting.

First lets start with the arduino using the receiver.

Connect the led as we did on part one ( for this part I got it on Digital Pin 10)

Check where are the GND / DATA / VCC of the receiver and connect accordingly on the power buses and the data to Digital Pin 6.

Don't forget to connect the arduino with the power buses.

Now let's focus on the transmitter.

As previously connect arduino with the breadboard power buses.

Now attach the transmitter and the motion sensor(using the female to male cables) to the breadboard.

As you can see in the photos I have the OUT of motion sensor connected to Digital Pin 7 and the DATA of transmitter to Digital Pin 9.

That's it. You finished connecting for the 2nd part.

Coding time...

STEP 6: Part 2 : Coding

TRANSMITTER CODE

------------------------------------------------------------------------

#include

const int led_pin = 13;

const int transmit_pin = 9;

const int sensor_pin = 7;

int sensor_value;

void setup() {

vw_set_tx_pin(transmit_pin);

vw_setup(2000);

pinMode(led_pin, OUTPUT);

pinMode(sensor_pin,INPUT);

}

void loop() {

sensor_value = digitalRead(sensor_pin);

char msg[3] = {'o','f','f'};

if (sensor_value == 1){

msg[0] = 'o';

msg[1] = 'n';

msg[2] = '#';

}

digitalWrite(led_pin, HIGH);

vw_send((uint8_t *)msg, 3);

vw_wait_tx();

digitalWrite(led_pin, LOW);

delay(1000);

}

-----------------------------------------------------------------------------

RECEIVER CODE

----------------------------------------------------------------------------

#include

const int motion_pin = 10;

const int led_pin = 13;

const int transmit_pin = 9;

const int receive_pin = 6;

void setup() {

delay(1000);

Serial.begin(9600);

Serial.println("setup");

vw_set_rx_pin(receive_pin);

vw_setup(2000);

vw_rx_start();

pinMode(led_pin, OUTPUT);

pinMode(motion_pin, OUTPUT);

}

void loop() {

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) {

digitalWrite(led_pin, HIGH);

Serial.print("Got: ");

for (int i = 0; i < buflen; i++) {

Serial.print(char(buf[i]));

Serial.print(' ');

}

if(char(buf[2])=='#'){

digitalWrite(motion_pin, HIGH);

delay(1000);

digitalWrite(motion_pin, LOW);

}

Serial.println();

digitalWrite(led_pin, LOW);

}

}

-------------------------------------------------------------

STEP 7: Part 2 : Results

Dropbox link to Video is included so you can see how it should be working.

This is the end of Part 2.

Now let's continue with Part 3 and use the GSM Shield so we can call a number of our choise every time the sensor detects movement.

STEP 8: Part 3 : Hardware Setup

Grab some jumper cables and connect the Ground and the 5V to the power buses.

Use the female to male cables to connect your PIR motion sensor to your breadboard.

First connect the PIR sensor to the power buses as seen in the photo.

Before we start any connections with Arduino we will need to put the SIM card on GSM shield and the GSM shield on the Arduino board.

After that take a cable and connect the OUT of PIR sensor to a Digital Pin of your choice , for my project I will be using Digital Pin 7.

Now its time to connect our LED in the breadboard and via the resistor to the Digital Pin 10 as seen in the photo.

I believe i do not need to explain furthermore , but if someone needs help I would gladly help.

That is the end of the hardware for this part and this project.

Let's get to the code now...

STEP 9: Part 3 : Coding

#include

SoftwareSerial SIM900(7, 8); // configure software serial port

const int led_pin = 10;

const int sensor_pin = 7;

int sensor_value;

void setup() {

SIM900.begin(19200);

SIM900power();

delay(20000); // give time to log on to network.

pinMode(led_pin, OUTPUT);

pinMode(sensor_pin,INPUT);

}

void SIM900power()

// software equivalent of pressing the GSM shield "power" button

{

digitalWrite(9, HIGH);

delay(1000);

digitalWrite(9, LOW);

delay(5000);

}

void callSomeone() {

SIM900.println("ATDT + +302105432101");

// TRICKY PART use this if in the USA--> SIM900.println("ATD + +12128675309;");/dial US (212) 8675309/ // in my case Greece is SIM900.println("ATDT + +302105432101;"); / dial GR (210)(5432101)

// so basically its SIM900.println("ATD + +CountryCode_AreaCode_PhoneNumber);

delay(100);

SIM900.println();

delay(10000); // wait for 10 seconds...

SIM900.println("ATH"); // hang up

}

void loop() {

sensor_value = digitalRead(sensor_pin);

if (sensor_value == 1){

digitalWrite(led_pin, HIGH);

delay(1000);

digitalWrite(led_pin, LOW);

callSomeone(); // call someone

SIM900power(); // power off GSM shield

delay(600000); // delay 10 minutes till the next call.

}

}

STEP 10: Part 3 : Results

Dropbox link to Video is included so you can see how it should be working.

This is the end of Part 3 and the end of this Project. Hope you enjoy. Thank you.

https://www.dropbox.com/s/ov00mod4obysk4x/Arduino%...

Here are the Code files.

Have fun.

45 Comments

it's a wonderful project can you send me your project Block diagram and proteus design

Σε καταλαβαίνω ΟΚ.

Γιά όσους διαβάσουν το post βρήκα μιά λύση

Στέλνω στο gsm +++ από data mode σε command mode, αν δεν πάρω ΟΚ , ξαναστέλνω το

SIM900power, ή ρωτάω (AT+CSQ) τι ποιότητα σήματος έχει

ωραία η σκέψη σου καί η κατασκευή, αλλά μου δημιουργήθηκε ένα πρόβλημα, από μικροδιακοπές του δικτύου μάλλον, κάνει επανεκίνηση μόνο ο arduino με αποτέλεσμα το

void SIM900power που τρέχει στο setup να κλείνει το gsm

Υπάρχει τρόπος να ελέγχει άν είναι ΟΝ το gsm καί να μην στέλνει το SIM900power?

Ευχαριστώ, δυστυχώς δεν μπορώ να σε βοηθήσω. Έχουν περάσει 4 χρόνια από όταν έκανα το project και τουλάχιστον 3 από όταν χρησιμοποίησα arduino τελευταία φορά. Ελπίζω να βρεις την λύση. Καλή συνέχεια.

hello sir. i am doing the part 3 project and i am not using a breadboad which is i am just connecting the sensor and led on the gsm shield. and also i using the same code. unfortunately, it is not works. can you please help me. thankyou

Is it possible to just do the third part and skip the second one?

Hello, sorry for late answer.
So , yes. Consider each part as a different project.

are those part related to each other? or i can just built part 3 and not doing the other parts?

Figure it out. The answer is on the comment you just did a reply to.

Hi Sir, it it a nice project!
However, i am using SIM900A, i wonder how is the connection to arduino? please reply me =)

am a beginner so plzz tell where should i code and plzz dont regret the question

Do you have a schematic diagram for project 3? And if I want the alarm to activate at a certain time only, is it possible? How? :(

hello.i am trying to make it work.so for calling a Greek number is this right

SIM900.println("ATDT + +302105432101;"); / dial GR (210)(5432101) ?

To you really need ATDT ++ or is it something else?i can't get it call my number

Sir,

"#include <SoftwareSerial.h>"

Where is this file, is it built in library file of arduino or need to write separately

Hi,I have made the third part.. But when i tested it for the whole night i came to know that the project is calling on the phone itself after 55 min without sensing any motion ..plz help how we can solve this one...
Thanku in advance
Hi,
I have tried this thing but still i m facing same problem. I m not able to find the exect cause of my problem. In your program u r using a function
Sim900.power( );
What is the need of this function??

Sir,i am a beginner in Arduino. I tried this code in my Arduino uno and nano in the project. My PIR is working perfectly. it correctly worked in the 1st part. When I come to the 2nd part ,the transmitter is sending the data, but the receiver side shows no response. When I connect their pins by wire,it works.I am stuck in this part quite a while. Please help me in this.

More Comments