ESP32 CAM and PCA9685 PWM Servo Controller for Wi-Fi Controlled Servo Motor
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves an ESP32 CAM microcontroller, an Adafruit PCA9685 PWM Servo Breakout, an MG90S servo motor, and an MB102 Breadboard Power Supply Module. The ESP32 CAM controls the PCA9685, which in turn drives the MG90S servo motor. The MB102 Breadboard Power Supply Module provides the necessary power to the components.
Component List
ESP32 CAM
- Description: A microcontroller with integrated Wi-Fi and Bluetooth, suitable for IoT applications.
- Pins: 5V, GND, GPIO12, GPIO13, GPIO15, GPIO14, GPIO2, GPIO4, 3.3V, GPIO16, GPIO0, 3.3V / 5V / P_OUT, GPIO3 / RX, GPIO1 / TX
Adafruit PCA9685 PWM Servo Breakout
- Description: A 16-channel PWM driver, ideal for controlling servos and LEDs.
- Pins: 5.0V, GND, PWRIN, PWM7, PWM6, PWM5, PWM4, PWM3, PWM2, PWM1, PWM0, VCC, SDA, SCL, OE, PWM15, PWM14, PWM13, PWM12, PWM11, PWM10, PWM9, PWM8
MG90S
- Description: A micro servo motor commonly used in robotics and RC applications.
- Pins: SIG, VCC, GND
MB102 Breadboard Power Supply Module 3.3V/5V
- Description: A power supply module that provides 3.3V and 5V outputs for breadboard projects.
- Pins: VCC, GND, 3.3V, 5V
Wiring Details
ESP32 CAM
- 5V: Connected to VCC of MB102 Breadboard Power Supply Module
- GND: Connected to GND of MB102 Breadboard Power Supply Module and GND of Adafruit PCA9685 PWM Servo Breakout
- 3.3V: Connected to VCC of Adafruit PCA9685 PWM Servo Breakout
- GPIO3 / RX: Connected to SCL of Adafruit PCA9685 PWM Servo Breakout
- GPIO1 / TX: Connected to SDA of Adafruit PCA9685 PWM Servo Breakout
Adafruit PCA9685 PWM Servo Breakout
- GND: Connected to GND of ESP32 CAM, GND of MB102 Breadboard Power Supply Module, and GND of MG90S
- VCC: Connected to 3.3V of ESP32 CAM
- SCL: Connected to GPIO3 / RX of ESP32 CAM
- SDA: Connected to GPIO1 / TX of ESP32 CAM
- PWM0: Connected to SIG of MG90S
- 5.0V: Connected to VCC of MG90S
MG90S
- SIG: Connected to PWM0 of Adafruit PCA9685 PWM Servo Breakout
- VCC: Connected to 5.0V of Adafruit PCA9685 PWM Servo Breakout
- GND: Connected to GND of Adafruit PCA9685 PWM Servo Breakout
MB102 Breadboard Power Supply Module 3.3V/5V
- VCC: Connected to 5V of ESP32 CAM
- GND: Connected to GND of ESP32 CAM and GND of Adafruit PCA9685 PWM Servo Breakout
Code Documentation
ESP32 CAM Code
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Create the PCA9685 object
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // Minimum pulse length count (out of 4096)
#define SERVOMAX 600 // Maximum pulse length count (out of 4096)
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates
void setup() {
Serial.begin(115200);
Serial.println("Initializing PCA9685...");
// Initialize the PCA9685
pwm.begin();
pwm.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
delay(10);
}
void loop() {
// Sweep the servo from min to max position
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
pwm.setPWM(0, 0, pulselen);
delay(10);
}
// Sweep the servo from max to min position
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(0, 0, pulselen);
delay(10);
}
}
This code initializes the PCA9685 PWM driver and sweeps the MG90S servo motor from its minimum to maximum position and back. The servo is connected to the PWM0 channel of the PCA9685.