Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 CAM and PCA9685 PWM Servo Controller for Wi-Fi Controlled Servo Motor

View and Edit Project In Cirkit DesignerImage of ESP32 CAM and PCA9685 PWM Servo Controller for Wi-Fi Controlled Servo Motor

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

Adafruit PCA9685 PWM Servo Breakout

MG90S

MB102 Breadboard Power Supply Module 3.3V/5V

Wiring Details

ESP32 CAM

Adafruit PCA9685 PWM Servo Breakout

MG90S

MB102 Breadboard Power Supply Module 3.3V/5V

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.