Skip to content
All projects

Computer Vision Face-Tracking Turret

A webcam on a servo that finds your face and follows it.

Summary

What it is
A single-axis face-tracking camera turret
Team
Solo (personal project)
Dates
Aug 2026
Tools
Python, OpenCV (Haar cascades), Arduino Mega, servo, serial communication
Results
Stable tracking after Kp tuning (0.05 → 0.035 degrees of pan per pixel of error) and a 15 px deadzone
Servo signal
Mega pin 6
Serial
9600 baud
Power
USB from the laptop; servo on the Mega's 5V pin

What I built

  • A single-axis face-tracking camera turret: Python + OpenCV (Haar cascades) detects a face on a USB webcam and streams pan angles over serial to an Arduino Mega driving the servo.
  • I eliminated oscillation by tuning a proportional controller (Kp stepped down from 0.05 to 0.035 degrees of pan per pixel of error, applied each frame) and adding a 15-pixel deadzone around the frame centre.
  • I debugged the full stack: inverted control direction from servo mounting, an OpenCV 5 API break (pinned to 4.x), and Windows camera-backend errors.
Hand holding the webcam-on-servo turret, with the Arduino Mega wired up behind
Munhib at a desk holding the turret, with the laptop showing the OpenCV feed

How it works

  1. A USB webcam feeds the laptop. Python + OpenCV finds the face with Haar cascades, which is classical computer vision.
  2. Proportional control: each frame, the pan angle changes by Kp degrees per pixel of error, with a 15-pixel deadzone around the frame centre.
  3. The laptop streams pan angles over serial at 9600 baud to an Arduino Mega. The servo signal is on Mega pin 6. Everything is powered over USB from the laptop, with the servo on the Mega's 5V pin.
System blocks: webcam to laptop running Python and OpenCV, USB serial at 9600 baud to the Arduino Mega, PWM on pin 6 to the servo. Below, the Mega's GND, 5V and pin 6 wired to the servo.
System block diagram and Mega-to-servo wiring (the same file as in the repo)

Results

0.05 → 0.035
Kp, degrees of pan per pixel of error
15 px
Deadzone around the frame centre

Stable tracking after Kp tuning and the deadzone.

What went wrong

  1. 01

    Oscillation

    At Kp 0.05 the turret oscillated. Stepping Kp down to 0.035 and adding the 15-pixel deadzone eliminated it.

  2. 02

    Inverted control direction

    The control direction was inverted because of how the servo was mounted.

  3. 03

    OpenCV 5 API break

    An API break in OpenCV 5. I pinned OpenCV to 4.x.

  4. 04

    Windows camera backend

    Windows camera-backend errors.

Next steps

Finish the 3D-printed webcam bracket (the webcam is currently taped to the servo horn), then reshoot the demo.