Introduction: 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.
Participated in the
Sensors Contest