Follow Me CAM

STORY

Our team came up with this idea to solve a problem. I was having a problem with the camera. Most of us are familiar with that one particular camera which is positioned on a wall between two rooms, however, you can only see one room at a time unless you log into the camera software to rotate it manually.  If someone were to walk into the opposite room, the camera would never record the action.  To solve this problem, we decided to create a motion detecting/tracking base on which we could attach the camera so it would automatically reposition itself to wherever the motion was detected.

 

HOW IT WORKS 

This device uses 5 PIR motion sensors to detect any movement within an 180º radius.  Once motion is detected, a servo motor rotates the camera base to point in that direction.  There are also 5 LED “status” lights positioned inside the base that will light up anytime one of the PIR sensors detects motion.

 

THINGS USED IN THIS PROJECT

PARTS

QUANTITIES

SUPPLIERS

ARDUINO UNO 1 WORLDWIDE
CAPICITOR 100 µF 1
LED (generic) 1  “
PIR Motion Sensor (generic) 1  “
Resistor, 220 ohm 1  “
Servo (generic) 1

 “

Wiring :

The wiring for this project is simple and straightforward, however, due to the fact that there are 5 of everything except the servo motor, the number of wires starts to add up quite a bit.  Check out the circuit diagram and schematics at the bottom of this page for more details, but here are the basics.

The LED status 

I used a mini breadboard to keep the LED lights separate from the rest of the circuitry in order to allow for easier removal if needed.  Each LED responds to a different PIR sensor and will light up anytime it detects motion.  Simply connect each LED to a separate digital input (9-13) on the Arduino, and ground them through a 220-ohm resistor.

The PIR motion sensors

I used the HC-SR501 model PIR sensors for this project.  Each PIR sensor needs to be connected to a digital input (2-6) on the Arduino, 5V power, and ground.  If you’re using the same PIR sensor as me, you can (carefully) pop off the cover and the pins are marked underneath.  You’ll connect each PIR sensor to the corresponding LED light in the code uploaded later.

The servo motor

The servo motor is attached to the stand where the camera sits and rotates the camera to align with the active PIR sensor.  Using the pinout for your motor, connect one pin to power, another pin to the Arduino digital input 7, and the last pin to ground.  Before powering the Arduino, make sure to connect a 100µF capacitor between the power and ground of the motor to help protect the board from the power surges that occur when the motor moves.  

SCHEMATICS

screenshot-37

CIRCUIT DIAGRAM

screenshot-39

HOW TO MADE A STAND ?

screenshot-40screenshot-41

LET’S DO CODING!

// Servor motor
#include <Servo.h>
Servo camServo; // name the servo motor controlling the camera base
int currentPIRposition = 0; // set current angle of servo
// LED status lights
int LEDpin[] = {9,10,11,12,13}; // LED pin numbers
int currentLEDpin = 9; // the current LED pin; begin with the first in the sequence above
// PIR sensors
int PIRpin[] = {2,3,4,5,6}; // PIR pin numbers
int currentPIRpin = 2; // the current PIR pin; begin with the first in the sequence above
int PIRprevState[] = {1,1,1,1,1}; // the previous state of the PIR (0 = LOW, 1 = HIGH)
int PIRposition[] = {157,117.75,78.5,39.25,0}; // assign angles for servo motor (0-157 distributed equally between 5 PIR sensors)
boolean PIRstatus; // Set status of PIR sensor as either true or false
///// SETUP //////////////////////////////////////
void setup() {

Serial.begin(9600);
camServo.attach(7); // assign servo pin

for (int p = 0; p < 5; p++) { // set all PIR sensors as INPUTS
pinMode(PIRpin[p], INPUT);
} // end ‘p’ for

for (int l = 0; l < 5; l++) { // set all LEDs as OUTPUTS
pinMode(LEDpin[l], OUTPUT);
} // end ‘l’ for

/////// CALIBRATE PIR SENSORS ///////
Serial.print(“Calibrating PIR Sensors “);
for(int c = 0; c < 15; c++){ // calibrate PIR sensors for 15 seconds (change from 10-60 sec depending on your sensors)
Serial.print(“.”);
delay(1000); // wait 1 second
} // end calibration for
Serial.println(“PIR Sensors Ready”);

camServo.write(78.5); // move the servo to the center position to begin

} // end setup

///// MAIN LOOP //////////////////////////////////
void loop() {

for (int PIR = 0; PIR < 5; PIR++) { // start this loop for each PIR sensor
currentPIRpin = PIRpin[PIR]; // set current PIR pin to current number in ‘for’ loop
currentLEDpin=LEDpin[PIR]; // set current LED pin to current number in ‘for’ loop
PIRstatus = digitalRead(currentPIRpin);

if (PIRstatus == HIGH) { // if motion is detected on current PIR sensor
digitalWrite(currentLEDpin, HIGH); // turn corresponding LED on
if(PIRprevState[PIR] == 0) { // if PIR sensor’s previous state is LOW
if (currentPIRposition != currentPIRpin && PIRprevState[PIR] == 0) { // if high PIR is different than current position PIR then move to new position
camServo.write(PIRposition[PIR]);
Serial.print(“Current angle : “);
Serial.println(PIRposition[PIR]);
delay(50);
currentPIRposition = currentPIRpin; // reset current PIR position to active [PIR] pin
PIRprevState[PIR] = 1; // set previous PIR state to HIGH
}
PIRprevState[PIR] = 1; // set previous PIR state to HIGH if the current position is the same as the current PIR pin
} // end PIRprevState if
} // end PIRstatus if

else { //
digitalWrite(currentLEDpin, LOW); //the led visualizes the sensors output pin state
PIRprevState[PIR] = 0; // set previous PIR state to LOW
} // end else

} // end [PIR] for loop
} // end main loop


If you have any kind of doubts just post as comments below. I will try my best to revert the solutions to you ASAP.

Yaaaeyy! you made it 🙂

Happy Interfacing

Shubham Gupta

TECEX Inc.

 

 

Advertisements

One thought on “Follow Me CAM

  1. This is the perfect webpage for anyone who wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I really would want laugh out loud). You certainly put a new spin on a subject which has been discussed for a long time. Great stuff, just excellent!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s