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

Picture of 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

Picture of 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

Picture of 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

Picture of Part 1 : Results

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

Picture of 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 <VirtualWire.h>

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 <VirtualWire.h>

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

Picture of Part 2 : Results

Video is 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 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

Picture of 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.h>

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

Picture of Part 3 : Results

Video is 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 3 and the end of this Project. Hope you enjoy. Vote me at the sensor contest. Thank you.

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

Here are the Code files.

Have fun.

Comments

idayu_ismail (author)2017-01-08

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

JazlynA (author)2016-09-20

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

Batonikos (author)JazlynA2016-09-21

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

idayu_ismail (author)Batonikos2016-12-16

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

Batonikos (author)idayu_ismail2016-12-16

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

js0902 (author)2016-11-21

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

JashwanthR2 (author)2016-10-07

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

JazlynA (author)2016-09-25

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? :(

Vasilisro1 (author)2016-07-02

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

UttamD3 (author)2016-05-19

Sir,

"#include <SoftwareSerial.h>"

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

Batonikos (author)UttamD32016-05-19

Hello, here you go

https://www.arduino.cc/en/Reference/SoftwareSerial

it is a built in library.

Do your research before asking please :D

SonuB4 (author)2015-11-20

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

Batonikos (author)SonuB42015-11-27

Ok so had a little bit extra time and searched a bit on how to solve tis problem and found this. Still not tested but think it will work.

void(* resetFunc) (void) = 0; //declare reset function @ address 0

And add resetFunc(); //call reset after the delay(600000);

Found at https://www.instructables.com/id/two-ways-to-reset-arduino-in-software/

SonuB4 (author)2015-11-23

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??

Batonikos (author)SonuB42015-11-25

Ok so had a little bit extra time and searched a bit on how to solve tis problem and found this. Still not tested but think it will work.

void(* resetFunc) (void) = 0; //declare reset function @ address 0

And add resetFunc(); //call reset after the delay(600000);

Found at https://www.instructables.com/id/two-ways-to-reset-arduino-in-software/

adilmohd12 (author)2015-09-07

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.

Batonikos (author)adilmohd122015-09-13

Hello, not really sure what in particular is the reason you have problem but some guesses here:
1)You have not installed VirtualWire or installed it at wrong folder.
2)Your receiver is broken or your wires are put on wrong breadboard slots.
3)Check that code and arduino inputs match.

That's all I can think of now.
Hope this helps.

adilmohd12 (author)Batonikos2015-09-18

When i connect transmitter pin to receiver pin , the program works. That means virtualwire is working. When i check the voltage of transmitter and receiver by multimeter, it does not show anything. And my transmitter and receiver used to work in previous projects.

CatLus (author)2015-07-22

Can I use this in my course study? Ill just add some innovations but right now I still cant think of any. I am just asking for a permission in advance. Thank you. :D

Batonikos (author)CatLus2015-07-30

Feel free to use it

landraka (author)CatLus2015-07-23

Yes of course, its all open source. I recommend using a wifi shield to use transmit data from a webcam recording in the room. That would be a cool add on project!

CatLus (author)landraka2015-07-23

Thank you so much. :D

CédricV2 (author)2015-05-28

Hi everyone,

One could also use https://kerberos.io/, it runs on the Raspberry Pi and it's also open source.

MuhammadS24 (author)2015-05-17

why this connection is not working>>?? can u help me>??? pleasee :(

amâdnêŝŝ1 (author)2015-04-19

Can i replace the calling option with a camera module to send a direct picture?

Royer.Yagami.Rodriguez (author)2015-04-12

good (y)

mustafak5 (author)2015-04-11

Nice and good job ... thank you so much

ay_kh (author)2015-03-20

Which language is used here ??

Batonikos (author)ay_kh2015-03-21

I am not going to answer non project related questions.

Search Google about Arduino you will find your answer.

Bartman12345 (author)2015-02-08

So in the end, are you only using ne arduino uno board?

Batonikos (author)Bartman123452015-02-09

Depends which part are you referring to?

Part_1 and Part_3 use only one Arduino Uno board.

Part_2 uses 2 Arduino Uno boards

Bartman12345 (author)Batonikos2015-02-09

Oh, wait. I think I get it. Part 1 is about using an arduino and PIR to set something off( LED, buzzer, ect.) , Part two is about how to do the same thing, but transmitting the signal between two boards. Part 3 is how to use 1 arduino, PIR, and a GSM to call your phone when a motion is sensed. Am I right?

Batonikos (author)Bartman123452015-02-10

Exactly , it is probably my fault. Shouldn't have named them Parts. Think of each Part as a different Project.

Bartman12345 (author)Batonikos2015-02-09

I'm asking about the finial project. I'm wanting to know how many arduino boards you use for the motion sensor that calls your phone- part 3. To clarify, I'm wanting to know on step 3, which calls your phone if motion is sensed, how many boards are used. Also you can use an arduino nana, instead of a uno can't you?

Bartman12345 (author)Batonikos2015-02-09

Does part 3, sense movement and call your phone? If so, what are parts one and two for? Can you list what each step is for?
Like step one is blah blah. Love the idea, hope to see more.

KOTSOS5 (author)2014-12-20

Very nice instructable! Μπράβο πολύ καλή δουλειά!

Dimosthenis.Ch (author)2014-10-25

Very interesting project and excelent presentation on top of that!

Timofte Andrei (author)2014-05-31

can you put a link with the arduino sketch here on instructables? it seems that the text editor removes some parts of the code and this is really annoying.

Batonikos (author)Timofte Andrei2014-05-31

Just uploaded to dropbox since it doesnt need seeding like torrent.

Click link and download the .ino files.

Timofte Andrei (author)Batonikos2014-05-31

thanks alot!anyways i will use some of your code in my university degree project :D if you want you can check my projects as well :D thanks again!

Batonikos (author)Timofte Andrei2014-05-31

Thank you for telling me. So i fixed the libraries that weren't shown. If you still got problem please reply and i will upload a file with the code so you can download as a .rar file