This project teaches students how to control a servo motor using the ESP32 microcontroller and MicroPython. Students will learn how PWM signals correspond to angular movements and how to control the servo to move to specific angles. This is commonly used in robotic arms, steering mechanisms, and automated systems.
ESP32 GPIO23 —> Signal (Servo)
ESP32 5V or Ext PSU —> VCC (Servo)
ESP32 GND —> GND (Servo)
from machine import Pin, PWM
from time import sleep
# Setup PWM on GPIO 23
servo = PWM(Pin(23), freq=50)
# Helper function to set angle
# Servo expects duty between ~40 (0°) and ~115 (180°)
def set_angle(angle):
duty = int((angle / 180) * 75 + 40) # scale 0–180 to 40–115
servo.duty(duty)
# Main loop
while True:
print("Rotating to 0°")
set_angle(0)
sleep(1)
print("Rotating to 90°")
set_angle(90)
sleep(1)
print("Rotating to 180°")
set_angle(180)
sleep(1)
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.