Maker Pro
Arduino

How to Add Motion Tracking to Your Camera With Arduino

March 21, 2018 by Jeff Salim
Share
banner

Create a motion-tracking base so your security camera can automatically reposition itself wherever motion is detected.

I came up with this idea to solve a problem I was having with my home security cameras. I have one particular camera that 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, I decided to create a motion detecting/tracking base on which I could attach the camera so it would automatically reposition itself to wherever the motion was detected. So let's start building this Arduino Security Camera.

How Does the Motion-Tracking Camera Work?

This Arduino Security Camera uses 5 PIR motion sensors to detect any movement within a 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.

Wiring the Arduino Security Camera

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 below to make the connections for your Arduino Security Camera.

LED status lights

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.

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 are using the same PIR sensor as me, you can (carefully) pop off the cover and the pins are marked underneath. You will connect each PIR sensor to the corresponding LED light in the code uploaded later.

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.

One thing to note about servo motors is that not all have a full 180º range of motion. So modify the code accordingly if your motor differs. You'll know the motor is trying to move too far when it makes a grinding noise at the last PIR sensor position.

Uploading the Code for the Arduino Security Camera

Now try uploading the code for the Arduino Security Camera. Be sure to download the code.

Making the Security Camera Base

I used an old Memorex cd labeler for the servo housing and the surface for our Arduino Security Camera to sit on. I failed to take a ‘before’ picture, so the image on the right is the only remaining one that I could find online. The back piece was a flat, sturdy plastic disc that eventually came off in one piece (after a little persuasion from my screwdriver), so that worked out great for a place to seat my camera. It also came with 4 removable rubber ‘feet’, which helps to give the camera a little more grip when the motor moves.

I took my pliers to the black part in the center to remove it. And by that I mean, break it into as many parts as I can before it’s gone. Next, I drilled a couple of holes in the base with my Dremel and then attached the servo motor with a couple of screws.

Lastly, I used another screw to attach the servo motor to the piece where the camera will sit. I ran into an issue where the weight of the camera was causing the base to tilt, so I solved this by making a cardboard cylinder just tall enough to fit loosely between the motor and the camera. Now it still moves freely, but has more support with it’s weight evenly distributed.

The servo motor is attached to the CD labeller's base, and the bottom piece is reused as the surface to seat the camera. The circular cardboard is added between the two pieces for stability.

You can follow the instructions in the below images to cut out and assemble your cardboard base for the Arduino Security Camera.

Putting It All Together

Here's what everything looks like after the PIR sensors have been installed and all the circuitry completed. Each of the five sections has a PIR motion sensor. You will notice I used several breadboards to complete my project. The reason for this being that it made it extremely easy to fit them inside the base, as well as pick and choose which one to remove while troubleshooting and expanding upon later.

To complete the Arduino Security Camera t, I spray-painted all the visible parts of the cardboard black. So that it looked more seamless with the black stand above. Here is the finished Arduino Security Camera after painting.

Now hook up your existing camera and see how it follows motion and captures video at the right angles. You can use your wired webcam or even have a Raspberry Pi to stream the video over wifi.

Related Content

Comments


You May Also Like