![tittle.jpg](https://static.wixstatic.com/media/fa678f_d61d4f3e9d764ab89680ef70f4831689~mv2_d_4032_1428_s_2.jpg/v1/fill/w_979,h_301,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/tittle.jpg)
INTRO .
We are going to see how to built a camera that can detect and track faces .
![](https://static.wixstatic.com/media/fa678f_49d6c4b04a4146baabddac8e0f293fb5f000.jpg/v1/fill/w_147,h_83,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_49d6c4b04a4146baabddac8e0f293fb5f000.jpg)
HOW DOES IT WORK ??!
A webcam capture and feeds images to a program running on a computer .
The program process the images to detect faces .
If no face is detected in the image the camera will start randomly roaming until it finds a face to track .
If a face is detected the camera will try to move to get the detected face in the centre of image .
The camera movement is handled by 2 servos controlled by an arduino Uno communicating with the face tracking program using serial communication through USB .
The 3 LED's on the case let us know the state of the tracking :
- Red : no face detected .
- Yellow : face detected but not in the center of the image .
- Green :face detected and in the center of the image .
WHAT YOU NEED .
*** disclaimer : some of the links below are affiliate links, this means I get a small commission when you purchase using them ( at no extra cost to you ) . If you like this website please consider using them but you don't have to ! ***
![electronic_display_black.jpg](https://static.wixstatic.com/media/fa678f_79c26a23698644479f69aaee46718d6f~mv2_d_4032_2268_s_2.jpg/v1/fill/w_142,h_80,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/electronic_display_black.jpg)
- Arduino Uno R3
- 2 x MG-90S servos (You can also use SG-90 servos)
- Webcam
- Power supply ( needs to deliver over 7 volts and 2 amps )
- 5V voltage regulator
- 2.1x5.5mm jack plug
- male pin header
- heatshrink tubing
- M2x10mm self tapping screw
- rubber band ( you can also use zip ties )
- paperclip
- wires
- 3 x LED ( optional )
- 3 x 220 ohm resistor ( optional )
TOOLS .
![tools_black.jpg](https://static.wixstatic.com/media/fa678f_5a737c5e33b647fdb6d026f3befef39c~mv2_d_4032_2268_s_2.jpg/v1/fill/w_147,h_83,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/tools_black.jpg)
- screwdriver
- something to check dimensions, a ruler or a caliper
- wire stripper
- pliers
- soldering iron
- multi-meter .
PARTS
*** If you do not have access to a 3D printer check the
FACE TRACKING CAMERA CARDBOARD version . ***
Here are the 8 parts you will need to print :
- Camera holder arm
- Upper bracket
- Lower bracket
- LED lock
- Short axle end
- Long axle end
- Stand
- Case
![parts_display_black.jpg](https://static.wixstatic.com/media/fa678f_c43188bbd03b41788e0adb682ae24d93~mv2_d_4032_2268_s_2.jpg/v1/fill/w_147,h_83,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/parts_display_black.jpg)
CASE
CAMERA HOLDER ARM
UPPER BRACKET
LOWER BRACKET
LED LOCK
STAND
SHORT AXLE END
LONG AXLE END
ASSEMBLY .
![](https://static.wixstatic.com/media/fa678f_fbfd10deeaed493c969fea8e62723097~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_fbfd10deeaed493c969fea8e62723097~mv2_d_4032_2268_s_2.jpg)
1 . Fit the upper bracket to the camera holder arm using the short axle end (on the side of the camera holder arm with the groove ) .
2 . Screw the long axle end to the upper bracket .
Make sure the parts move freely but without excessive play .
![](https://static.wixstatic.com/media/fa678f_f4c98d3c55734696a14cd76a214c1283~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_f4c98d3c55734696a14cd76a214c1283~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_3dd3ca04ba704a1bb82cc82fe5fd8f55~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_3dd3ca04ba704a1bb82cc82fe5fd8f55~mv2_d_4032_2268_s_2.jpg)
3 . If your webcam has a stand, remove it .
4 . Use a few rubber bands to hold the webcam on its arm .
![](https://static.wixstatic.com/media/fa678f_ccb57410e8d4483cab552e6f228eb1ce~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_ccb57410e8d4483cab552e6f228eb1ce~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_c01dd2068a294a878bbadbd34c5c4467~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_c01dd2068a294a878bbadbd34c5c4467~mv2_d_4032_2268_s_2.jpg)
5 . Screw the pan servo onto the upper bracket . Hold the servo and webcam cables between the servo and the upper bracket .
6 . Screw the tilt servo onto the upper bracket .
![](https://static.wixstatic.com/media/fa678f_63f89dec8ea148f3acf30972b5df223b~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_63f89dec8ea148f3acf30972b5df223b~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_2c2efd1f5d9c4eefa3a0c7cffc670c62~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_2c2efd1f5d9c4eefa3a0c7cffc670c62~mv2_d_4032_2268_s_2.jpg)
7 . Fit the lower bracket and screw both servos on it .
8 . Screw the stand on the case .
![](https://static.wixstatic.com/media/fa678f_48d99e6e579346ca9dc3434469fc7688~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_48d99e6e579346ca9dc3434469fc7688~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_1f595c38770c419fad51a727e44c6420~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_1f595c38770c419fad51a727e44c6420~mv2_d_4032_2268_s_2.jpg)
9 . Screw the pan servo horn on the stand and trim any excess length .
10 . Unfold the paper clip to get a straight rod . Then create a couple of 90 degrees bends 30 mm apart .
![](https://static.wixstatic.com/media/fa678f_e81bf21bb0a04732a131d090972e7f4f~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_e81bf21bb0a04732a131d090972e7f4f~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_0d1cc5f4f8df487ea8b3e7c676548636~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_0d1cc5f4f8df487ea8b3e7c676548636~mv2_d_4032_2268_s_2.jpg)
11 . Fit one end of the rod in the pinhole on the side of the camera holder arm .
Then slide the tilt servo horn on the other end .
We will need to set up the servos before bolting the horn onto the servo .
12 . Mark the tilt servo wire . It will help to identify each servo once everything is assembled .
![](https://static.wixstatic.com/media/fa678f_c9a579493dbe497f899e62750d0d2629~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_c9a579493dbe497f899e62750d0d2629~mv2_d_4032_2268_s_2.jpg)
![](https://static.wixstatic.com/media/fa678f_49a96cd8f763499386117b2cc39bf761~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_49a96cd8f763499386117b2cc39bf761~mv2_d_4032_2268_s_2.jpg)
13 . Pass the servo wires through the hole at the top of the case .
14 . You can then temporary mount the camera assembly to the case .
It will have to come off after setting up the servos .
![](https://static.wixstatic.com/media/fa678f_28be687110124acd86f8c806eee4c7a7~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_28be687110124acd86f8c806eee4c7a7~mv2_d_4032_2268_s_2.jpg)
The assembly is pretty much done !!! We just have to take care of the wiring before being able to bolt the servo horns in their final position .
WIRING .
![](https://static.wixstatic.com/media/fa678f_d9fa91e67dd746568d172ddc9a501f2e~mv2.png/v1/crop/x_586,y_155,w_1230,h_779/fill/w_85,h_54,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_d9fa91e67dd746568d172ddc9a501f2e~mv2.png)
![](https://static.wixstatic.com/media/fa678f_f71b16efb63342b7bdb82fbbba37edd7~mv2_d_4032_2268_s_2.jpg/v1/fill/w_108,h_61,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/fa678f_f71b16efb63342b7bdb82fbbba37edd7~mv2_d_4032_2268_s_2.jpg)
Once everything is done you should end up with something like this .
wiring photo assembly here
software (and servos setup) .
We will now see how to use the software and setup the servos .
The software comes in 2 version :
- An executable that you just have to download and run (this is great if you can't code . unfortunately this only works on windows) .
- And a repository including all the python, UI and haar cascade file required to run the program . Feel free to improve and build upon the existing code !
1 . The software comes with an arduino sketch named "Camera_tracking.ino" .
Upload it to the arduino .
Then unplug the arduino from the computer .
2 . Temporary plug the servos to the arduino then plug the power supply to the jack .
The sketch we just uploaded includes a starting routine that involve the position of both servo to be set at 90 degrees .
3 . Carefully unscrew the pan servo horn without changing the servo position and remount the camera facing forward .
4 . Fit the tilt servo horn to get the camera to point straight forward .
5 . Fit the jack and voltage regulator to the case .
6 . Fit the LED's to the case using the LED lock part .
6 . Seal everything by screwing the arduino to the case .
7 . Plug the power supply to your arduino, plug the arduino to you computer and don't forget to also plug the USB webcam .
Then start the face tracking software .
8 . You might get a warning message since I am not a certified Microsoft developer . You can ignore it or if you don't trust me use the python file and check the code for yourself . I won't blame you for Being too careful !!!