🪂

Final Project Servo Mechanism

🌐 Home

👋 About

Hero Shot

Summary

For the output device assignment, I integrated a servo motor with my XIAO ESP32-C3 microcontroller. The goal was to test basic PWM-based control for mechanical movement, which is crucial for my final project—specifically for triggering physical actions like parachute release. This task gave me hands-on experience in working with digital output devices and real-time control logic.

Work Process Detail

1. Servo Motor Selection

  • I used a standard SG90 servo motor, which is lightweight and ideal for compact applications like rockets and mechanical triggers.
  • Operating voltage: 3V – 6V
  • PWM signal control with 0–180° movement range

2. Circuit Setup

  • Connected the servo signal pin to GPIO 3 on the XIAO ESP32-C3.
  • Connected 5V power to the servo using an external power source to avoid overloading the microcontroller.
  • GND lines of the ESP32, servo, and power source were all connected to ensure a common reference.
    • [ESP32 GPIO 5] -------> [Servo Signal]
      [3.3V External Power] --> [Servo VCC]
      [Common Ground] ------> [Servo GND] + [ESP32 GND]

3. Code Implementation

  • Used the ESP32Servo library to generate the required PWM signals.
  • The servo was programmed to rotate between defined angles in a loop to simulate mechanical motion like locking/unlocking or latching.
#include <ESP32Servo.h>

Servo myServo;          // create servo object
int servoPin = 5;       // GPIO 3 on ESP32-C3
int angle = 0;          // variable to store the servo position

void setup() {
  Serial.begin(115200);
  myServo.setPeriodHertz(50);       // Standard 50 Hz servo
  myServo.attach(servoPin, 500, 2400); // Min and Max pulse width in µs
}

void loop() {
  // Sweep from 0 to 180
  for (angle = 0; angle <= 180; angle += 1) {
    myServo.write(angle);           
    delay(15);                      
  }

  // Sweep back from 180 to 0
  for (angle = 180; angle >= 0; angle -= 1) {
    myServo.write(angle);           
    delay(15);                      
  }
}

4. Testing & Results

  • Tested the servo sweep between 0° and 180°.
  • Ensured reliable motion and repeatability.
  • Confirmed that the servo can generate enough torque to trigger the mechanical latch for the parachute system.

Learning Outcome

From this task, I gained a clear understanding of:

  • Using PWM to control servos with the ESP32-C3.
  • Managing power distribution for motor-based output devices.
  • Verifying signal stability and physical performance of actuators.
  • Building a foundation for combining mechanical movement with sensor-based input logic.

Digital Files