ESP32 and 16-Channel PWM Servo Driver for Multi-Servo Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control multiple servos using an ESP32 microcontroller and a 16-Channel PWM Servo Driver. The ESP32 communicates with the PWM driver via I2C to control the position of the servos. Power is supplied through a 2.1mm Barrel Jack with Terminal Block.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
16-Channel PWM Servo Driver
- Description: A driver board that can control up to 16 servos using PWM signals.
- Pins: V+, VCC, SDA, SCL, OE, GND, Vin+, Vin-, PWM1, PWM2, PWM3, PWM4, PWM5, PWM6, PWM7, PWM8, PWM9, PWM10, PWM11, PWM12, PWM13, PWM14, PWM15, PWM16
2.1mm Barrel Jack with Terminal Block
- Description: A power input jack for connecting an external power supply.
- Pins: POS, NEG
Servo (Wokwi Compatible)
- Description: A standard servo motor compatible with Wokwi simulation.
- Pins: GND, V+, PWM
Wiring Details
ESP32 (30 pin)
- Vin is connected to V+ and VCC of the 16-Channel PWM Servo Driver.
- D22 is connected to SCL of the 16-Channel PWM Servo Driver.
- D21 is connected to SDA of the 16-Channel PWM Servo Driver.
- GND is connected to GND of the 16-Channel PWM Servo Driver.
16-Channel PWM Servo Driver
- V+ and VCC are connected to Vin of the ESP32.
- SCL is connected to D22 of the ESP32.
- SDA is connected to D21 of the ESP32.
- GND is connected to GND of the ESP32.
- Vin+ is connected to POS of the 2.1mm Barrel Jack with Terminal Block.
- Vin- is connected to NEG of the 2.1mm Barrel Jack with Terminal Block.
- PWM1 is connected to PWM of the first Servo.
- PWM2 is connected to PWM of the second Servo.
- PWM3 is connected to PWM of the third Servo.
- GND is connected to GND of the first, second, and third Servos.
- V+ is connected to V+ of the first, second, and third Servos.
2.1mm Barrel Jack with Terminal Block
- POS is connected to Vin+ of the 16-Channel PWM Servo Driver.
- NEG is connected to Vin- of the 16-Channel PWM Servo Driver.
Servo (Wokwi Compatible)
- PWM of the first Servo is connected to PWM1 of the 16-Channel PWM Servo Driver.
- PWM of the second Servo is connected to PWM2 of the 16-Channel PWM Servo Driver.
- PWM of the third Servo is connected to PWM3 of the 16-Channel PWM Servo Driver.
- GND of the first, second, and third Servos is connected to GND of the 16-Channel PWM Servo Driver.
- V+ of the first, second, and third Servos is connected to V+ of the 16-Channel PWM Servo Driver.
Documented Code
ESP32 Code
/*
* This Arduino Sketch is for controlling multiple servos using an ESP32 and a
* 16-Channel PWM Servo Driver. The ESP32 communicates with the PWM driver via
* I2C to control the position of the servos.
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
void setup() {
Serial.begin(115200);
Serial.println("Initializing PWM Servo Driver...");
Wire.begin(21, 22); // SDA, SCL pins
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}
void loop() {
// Example: Sweep servos connected to PWM channels 0, 1, and 2
for (uint16_t pulselen = 150; pulselen < 600; pulselen++) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(1, 0, pulselen);
pwm.setPWM(2, 0, pulselen);
delay(10);
}
for (uint16_t pulselen = 600; pulselen > 150; pulselen--) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(1, 0, pulselen);
pwm.setPWM(2, 0, pulselen);
delay(10);
}
}
16-Channel PWM Servo Driver Code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This documentation provides a comprehensive overview of the circuit, including a summary, component list, wiring details, and the code used for the microcontrollers.