Arduino: Controlling Multiple Servos with ESP32
|ESP32 supports many development platforms such ESP-IDF, MicroPython and Arduino.We had already seen how to interface servo with esp32 using ESP-IDF and MicroPython. In this post we will see how to control multiple servos using ESP32 on arduino platform.
WHAT YOU NEED
- Arduino IDE with ESP32 framework installed
- ESP32 Servo library for arduino
- ESP32 Dev board (any board the exposes the GPIOs should work)
- Two servo motors and jumper wires
If you haven’t installed servo library, checkout this post which will guide you through installation process.
Connecting servos to ESP32
I am using IO12 (servo1) and IO22 (servo2) but most of the other IOs should also work. I am using 9g servo, power supply from dev board should be enough for this. For large servos, you might want to use a dedicated power supply.
Servo 1
- orange – IO12
- red – +5v
- brown – GND
Servo 2
- orange – IO22
- red – +5v
- brown – GND
Sweeping multiple servos
Following code will sweep all connected servos from 0 to 180 and back 0. We need to provide number of connected servos and IO pin for each servo. Code will loop through each servo and sets the angle appropriately.