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

Arduino UNO and Adafruit PCA9685 Controlled Multi-Servo Tester

View and Edit Project In Cirkit DesignerImage of Arduino UNO and Adafruit PCA9685 Controlled Multi-Servo Tester

Circuit Documentation

Summary

This circuit is designed to control multiple micro servos using an Arduino UNO and an Adafruit PCA9685 PWM Servo Breakout board. The servos are connected to the PWM outputs of the PCA9685, which is controlled by the Arduino via I2C communication. The Arduino runs a sketch to test the wiring and functionality of the servos by rotating them back and forth.

Component List

Arduino UNO

Adafruit PCA9685 PWM Servo Breakout

Micro Servo 9G

Wiring Details

Arduino UNO

Adafruit PCA9685 PWM Servo Breakout

Micro Servo 9G (Instance 1)

Micro Servo 9G (Instance 2)

Micro Servo 9G (Instance 3)

Micro Servo 9G (Instance 4)

Code Documentation

Arduino UNO Code

/*
 * This Arduino sketch is designed to test the wiring of multiple servos
 * connected to an Adafruit PCA9685 PWM Servo Breakout board. The servos
 * will rotate back and forth to ensure that all connections are working
 * correctly.
 */

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup() {
  pwm.begin();
  pwm.setPWMFreq(60); // Analog servos run at ~60 Hz
}

void loop() {
  for (int pos = 0; pos <= 180; pos++) {
    setAllServos(pos);
    delay(15); // Wait for the servos to reach the position
  }
  for (int pos = 180; pos >= 0; pos--) {
    setAllServos(pos);
    delay(15); // Wait for the servos to reach the position
  }
}

void setAllServos(int pos) {
  int pulseLength = map(pos, 0, 180, 150, 600);
  pwm.setPWM(0, 0, pulseLength); // Servo 1
  pwm.setPWM(4, 0, pulseLength); // Servo 2
  pwm.setPWM(8, 0, pulseLength); // Servo 3
  pwm.setPWM(12, 0, pulseLength); // Servo 4
}

Adafruit PCA9685 PWM Servo Breakout Code

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup() {
  pwm.begin();
  pwm.setPWMFreq(60); // Analog servos run at ~60 Hz
}

void loop() {
  for (int pos = 0; pos <= 180; pos++) {
    setServoPosition(0, pos);
    delay(15); // Wait for the servo to reach the position
  }
  for (int pos = 180; pos >= 0; pos--) {
    setServoPosition(0, pos);
    delay(15); // Wait for the servo to reach the position
  }
}

void setServoPosition(int servoNum, int pos) {
  int pulseLength = map(pos, 0, 180, 150, 600);
  pwm.setPWM(servoNum, 0, pulseLength);
}