This circuit is designed to control six Tower Pro SG90 servo motors using two 8 push button board PCBs. The control logic is implemented on an Arduino UNO microcontroller, which interfaces with an Adafruit PCA9685 PWM Servo Breakout board to drive the servos. The servos are powered by a 5V battery connected to the PWM Servo Breakout board. The Arduino UNO communicates with the PCA9685 board via I2C using the SDA and SCL lines. Each servo motor's position can be adjusted using the corresponding pair of buttons on the push button boards.
/*
* This Arduino Sketch controls 6 servo motors using 12 buttons.
* Each pair of buttons controls one servo motor, with one button
* increasing the angle and the other decreasing it.
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
const int buttonPins[12] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
const int servoChannels[6] = {0, 1, 2, 4, 5, 6};
int servoAngles[6] = {90, 90, 90, 90, 90, 90};
void setup() {
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz
for (int i = 0; i < 12; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < 6; i++) {
if (digitalRead(buttonPins[i * 2]) == LOW) {
servoAngles[i] = min(servoAngles[i] + 1, 180);
}
if (digitalRead(buttonPins[i * 2 + 1]) == LOW) {
servoAngles[i] = max(servoAngles[i] - 1, 0);
}
pwm.setPWM(servoChannels[i], 0, angleToPulse(servoAngles[i]));
}
delay(15); // Small delay to debounce buttons
}
int angleToPulse(int angle) {
return map(angle, 0, 180, 150, 600);
}
The 5V battery does not have associated code as it is a power supply component.
This documentation provides an overview of the circuit, including the purpose and wiring of each component, as well as the embedded code running on the Arduino UNO microcontroller.