Inspiration

DARPA inspired this project. I admire how they take problems that sound impossible, build fast prototypes, and iterate until something works. I want to go into defense tech, so I wanted my first hackathon project to be a real system that senses, decides, and acts.

I pointed it at agriculture. Rodents destroy crops and stored grain, and the usual answers are poison or someone watching all night. Apex is a cheaper, automated version of that watch.

What it does

Apex uses a camera to find a target and aims a pan/tilt mount at it in real time. For the demo, it tracks a face as a stand-in for a pest. It follows one target at a time and holds position if it loses sight of it.

How I built it

A YOLOv8 face detection model runs on my laptop with OpenCV and finds the target in each frame. The script converts the target's position in the frame into a servo angle:

$$\theta_{pan} = 90^\circ \pm \left(\frac{x}{W} - 0.5\right) \cdot S$$

Here $x$ is the target's horizontal position, $W$ is the frame width, and $S$ is the pan range that matches the camera's field of view. Tilt works the same way. The angles are smoothed and sent over USB serial to an Arduino Uno, which drives two servos on a pan/tilt bracket from their own battery pack and glides to each new angle.

I also built and bench-tested a flywheel launcher circuit (two DC motors, a MOSFET, and a flyback diode) for a soft, non-lethal projectile. It works on its own but isn't integrated yet.

Challenges

This was my first hackathon and my first real electronics project, and I built it solo. Most of the work was debugging.

Wrong control model. My first tracking code assumed the camera rode on the turret, so it kept nudging the servos toward the target and never settled. It looked random. I switched to a fixed-camera approach that maps the target's position in the image directly to an aim angle, with manual trim to calibrate.

Servo jitter. Hobby servos have no position feedback, so a PID loop doesn't help. Smoothing, a deadzone, whole-degree commands, and a separate power supply with a shared ground fixed it.

Upload and port errors. My Mac's serial port number changed on every replug and I hit a bootloader "sync byte" error, so the script now finds the port automatically.

Pin conflicts and dependencies. My test code put the servos on the same pin as the flywheel motors, so I re-planned the layout. A dead model download link and numpy/OpenCV version mismatches cost me more time than I'd like to admit.

What I learned

  • Simple beats clever. Smoothing plus a direct position-to-angle mapping beat a more complex controller.
  • Power and wiring problems look exactly like software bugs, so test hardware alone first.
  • Know what your sensor is attached to before writing any control logic.

What's next

Integrate the launcher, replace face detection with real rodent detection, and mount the camera on the turret for closed-loop tracking.

Built with

Python, OpenCV, YOLOv8, PySerial, Arduino, servos

Built With

Share this project:

Updates

Submission history