Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

ESP32 Servo Motor with Arduino IDE

Introduction

Servo motors are precise actuators that rotate to a specific angle between 0° and 180°.
Using the ESP32’s PWM (Pulse Width Modulation) capabilities, you can control servo position easily.
This is useful for robotics, camera gimbals, and automation systems.

Required Components

  • ESP32 Dev Board
  • Servo Motor
  • Jumper wires
  • Breadboard
  • 5V Power Supply, Battery

Pinout

Circuit Diagram / Wiring

  • SERVO (5V) → ESP32 VIN an external 5V power supply
  • SERVO (GND) → ESP32 GND
  • SERVO (Signal) → ESP32 GPIO 13

Code / Programming

#include <Servo.h>

Servo myServo;

void setup() {
  myServo.attach(13); // Attach servo to GPIO 13
}

void loop() {
  myServo.write(0);    // Rotate to 0°
  delay(1000);
  myServo.write(90);   // Rotate to 90°
  delay(1000);
  myServo.write(180);  // Rotate to 180°
  delay(1000);
}

Explanation

  • Servo.h library simplifies PWM control of servos.
  • attach(13) links the servo signal to GPIO 13.
  • write(angle) rotates the servo to the desired position.

Testing & Troubleshooting

  • If the servo jitters or doesn’t move, check power supply stability.
  • Make sure the GPIO pin used supports PWM (most ESP32 GPIOs do).
  • Always connect the GND of the servo and ESP32 together.

    Leave a Reply

    Your email address will not be published.

    Need Help?