ESP32 with Servo Motor
A servo motor is a type of motor designed for precise control of angular position, making it ideal for applications like robotics, RC vehicles, automation, and control systems. It’s compact, easy to control using microcontrollers (like ESP32, Arduino, etc.), and widely used in DIY electronics.
🔧 1. What is a Servo Motor?
A servo motor is an actuator that rotates to a specific angle based on a control signal.
✅ Key Characteristics:
| Feature | Description |
|---|---|
| Type | Closed-loop control system |
| Rotation | Usually 0° to 180° (some 360° continuous) |
| Precision | High positional accuracy |
| Control Signal | PWM (Pulse Width Modulation) |
⚙️ 2. Internal Components of a Servo
Inside a typical servo motor:
- 🌀 DC Motor – Provides the rotation.
- ⚙️ Gearbox – Reduces speed, increases torque.
- 🎯 Potentiometer – Measures current position.
- 📢 Control Circuit – Compares target angle vs actual angle, adjusts motor.
This closed-loop system allows the servo to “know” where it is and adjust itself to reach the desired position.
📐 3. Types of Servo Motors
| Type | Description |
|---|---|
| Standard Servo | Rotates 0–180° (common in robotics) |
| Continuous Servo | Rotates 360° (acts like a DC motor with direction control) |
| High Torque Servo | For heavier mechanical loads |
| Micro Servo | Small, low-power (e.g., SG90) |
🔌 4. Servo Motor Pinout
Most servo motors have 3 wires:
| Wire Color | Function | Connects To |
|---|---|---|
| Red | VCC (5V) | 5V or 3.3V |
| Black/Brown | GND | GND |
| Yellow/Orange | Signal (PWM) | GPIO pin (e.g., D18) |
⚠️ Power your servo from an external source if it draws high current (>500mA).
🔁 5. How Servo Control Works
Servos are controlled using PWM (Pulse Width Modulation).
⏱️ PWM Signal Details:
- 50 Hz frequency (20ms period)
- Pulse width determines angle:
- 0.5ms – 1ms → 0°
- 1.5ms → 90°
- 2ms → 180°
The duration of the HIGH signal tells the servo what angle to move to.
🧠 6.ESP32 Servo Example Code
🛠 Required Library:
- Arduino:
Servo.h - ESP32:
ESP32Servo.h
✅ Basic Example:
#include <ESP32Servo.h>
#define GATE 18
Servo myservo;
void setup() {
myservo.attach(GATE);
Serial.begin(9600);
}
void loop() {
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(0);
delay(1000);
}⚠️ 7. Power Considerations
- Servo motors draw a lot of current, especially under load.
- Don’t power them directly from ESP32/Arduino’s 3.3V or 5V pin.
- Use a separate power supply (like 5V adapter or batteries) and connect GNDs together.
🧪 8. Common Uses of Servo Motors
- 🤖 Robotics – Arm joints, grippers, walkers
- ✈️ RC planes/cars/boats – Steering, throttle
- 🎮 Pan-Tilt camera systems
- 🧠 Automation systems – Smart locks, servo-based switches
- 🕹 Joystick-controlled actuators


Leave a Reply
You must be logged in to post a comment.