Mini air defense system
A robotic pan-tilt turret capable of detecting targets and launching projectiles using a flywheel mechanism.
Author: Condrea Vlad-Stefan
GitHub Project Link: https://github.com/UPB-PMRust-Students/acs-project-2026-Ionidis
Description
A smart robotic turret made using a STM32 NUCLEO board that acts as the main controller. The system uses a pan-tilt mechanical bracket driven by two MG996R servo motors to aim. An HC-SR04 ultrasonic sensor is mounted on the moving arm to detect the distance to a target. Once the target is within range, the Nucleo board triggers the flywheel launcher, which consists of two high-speed DC motors with rubber wheels that shoot the projectile. The entire system is powered by a LiPo battery, using an LM2596 step-down module to safely provide 5V to the servos and sensor. Added a joystick to the project so now I can manually control the turret and shoot the projectile by pressing the joystick button
Motivation
I believe that it would be a fun and challenging experience. I find robotics fascinating, and this project perfectly combines mechanical assembly, sensor data acquisition, and motor control using Rust. It acts as a great introduction to tracking systems and automated defense mechanisms.
Architecture
The system starts with the HC-SR04 ultrasonic sensor, which constantly sends distance data to the STM32 Nucleo controller.
The Nucleo board processes the sensor data to determine if a target is present. Based on the logic, it generates PWM signals sent directly to the two MG996R servo motors to adjust the Pan (horizontal) and Tilt (vertical) angles. When the target is locked, the Nucleo sends digital signals to a motor driver, which spins up the two DC motors of the flywheel launcher.
Power management is critical: a 7.4V LiPo battery supplies raw power to the motor driver for the DC motors. In parallel, the battery connects to an LM2596 Step-Down converter, which drops the voltage to a stable 5V to safely power the STM32 board, the HC-SR04 sensor, and the servo motors without frying them.
Main Architectural Components
Target Detection System (Input Data)
- Role: Continuously monitors the environment to detect potential targets and measure their exact distance from the turret.
- Components: 1x HC-SR04 Ultrasonic Sensor mounted on the moving pan-tilt bracket.
- Logic: The STM32 board sends a microsecond trigger pulse to the sensor, which then emits a sound wave. The board measures the duration of the returning echo signal to calculate the distance in real-time, feeding this data to the radar sweep algorithm.
The Central Logic Controller (Processing)
- Role: Acts as the brain of the system, executing the core algorithms, managing real-time hardware interrupts, and computing ballistic alignment (e.g., Center of Mass calculations and trigonometric offset compensation).
- Components: STM32 Nucleo-U545RE-Q Development Board.
- Logic: Uses the
embassyframework for asynchronous programming. It simultaneously handles spatial data acquisition, updates motor states, and coordinates the precise timing sequence for the firing mechanism without blocking the CPU.
Pan-Tilt Aiming System (Output)
- Role: Responsible for the physical orientation of the turret, allowing it to sweep, track, and lock onto targets across both horizontal (X) and vertical (Y) axes.
- Components: 2x MG996R High-Torque Servo Motors attached to a metal Pan-Tilt bracket.
- Logic: The microcontroller generates precise PWM (Pulse Width Modulation) signals. By altering the duty cycle, the board commands the servos to perform a radar-like scan, adjusting their angles to center perfectly on the detected object.
Flywheel Launcher System (Output)
- Role: Engages and accelerates the firing mechanism to launch the projectile at the locked target.
- Components: 1x L298N Motor Driver, 2x High-Speed DC Motors, and 2x Rubber Wheels.
- Logic: Upon confirming a target lock, the STM32 sends digital control signals to the IN pins of the L298N driver to set the rotation direction (wheels spinning inwards to grip and propel the foam dart). The L298N acts as a heavy-duty switch, delivering the high current required by the DC motors for the firing sequence.
Power Management Network
- Role: Distributes safe and stable operating voltages to all logic and mechanical components, preventing system resets under high mechanical loads.
- Components: 1x 7.4V LiPo Battery (Gens Ace 2S), 1x LM2596 Step-Down Module, and 1x LiPo Battery Tester/Buzzer.
- Logic: The power distribution is split into two branches. The raw 7.4V from the LiPo battery is routed directly to the L298N driver to provide maximum torque to the DC motors. In parallel, the LM2596 module steps down the 7.
Schematics
Log
Week 20 - 26 April
Got approval and researched the components. Ordered all the components.
Week 5 - 11 May
Assembled the mechanical pan-tilt bracket. Fixed alignment issues with the tilt servo and bearing. Attached the HC-SR04 sensor.
Week 12 - 18 May
Managed to power up all components by soldering all the wires needed to the step down module and the DC motors. The hardware is ready and can fully function.
Week 19 - 25 May
Wrote the code that has 2 modes one for am auto mode which tries to detect an object as precise as possible and a manual mode where I have a joystick to guide the turret.
Hardware
The project uses the Nucleo board as the brain. It receives echo pulses from the HC-SR04 sensor. After processing the distance, it sends PWM signals to the Pan and Tilt MG996R servos. It also controls a motor driver (L298N/L293D) to activate the dual DC motors for the launcher. The LM2596 acts as a power regulator.
Schematics
Bill of Materials
| Device | Usage | Price |
|---|---|---|
| STM32 Nucleo-U545RE-Q | Main Controller | Lab Provided |
| Metal Pan-Tilt Bracket | Mechanical structure for the arm | 20 RON |
| 2 x MG996R Servo Motor | Aiming (Pan and Tilt axis) | 60 RON |
| 2 x DC Motor | Flywheel projectile launcher | 8 RON |
| HC-SR04 Ultrasonic Sensor | Target detection and distance measuring | 14.5 RON |
| LM2596 Step-Down Module | Voltage regulator (Drops LiPo 7.4V to 5V) | 7 RON |
| L298N Motor Driver Module | Controls the DC motors for the launcher | 20 RON |
| Baterie Gens Ace G-Tech | Main power supply | 60 RON |
| Rotite cauciuc | Rotite care sa propulseze proiectilul din burete | 10 RON |
| Fire dupont | Fire pentru conecta componentele | 15 RON |
| Tester acumulator | Un buzzer care ma avertizeaza cand bateria este aproape sa se descarce | 10 RON |
| Incarcator | Pentru reincarcarea bateriei | 75 RON |
Software
| Library | Description | Usage |
|---|---|---|
| embassy-stm32 | Hardware Abstraction Layer | Handling GPIOs, EXTI (for sensor echo), and PWM peripherals (for servos) |
| embassy-executor | Async task executor | Managing concurrent tasks (sensor reading, aiming, shooting) |
| embedded-hal | Hardware abstraction traits | Standard interface for interacting with peripherals |
| defmt | Logging framework | Used for debugging distance readings and states |