Arduino UNO and 16-Channel PWM Servo Driver Controlled Robotic Arm with Battery Power
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control multiple servos using two 16-Channel PWM Servo Drivers and an Arduino UNO. The servos are powered by a 5V battery, and the Arduino UNO is used to send control signals to the PWM drivers, which in turn control the servos. The circuit includes four MG996R servos, each connected to one of the PWM channels on the servo drivers.
Component List
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 to PWM16
MG996R Servo Motor
- Description: A high-torque servo motor commonly used in robotics.
- Pins: GND, VCC, SIG
Arduino UNO
- Description: A microcontroller board based on the ATmega328P, used for various embedded applications.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0 to A5, SCL, SDA, AREF, D0 to D13
5V Battery
- Description: A power source providing 5V DC.
- Pins: positive, negative
Wiring Details
16-Channel PWM Servo Driver (1)
- V+: Connected to VCC of all MG996R servos
- VCC: Connected to 5V pin of Arduino UNO
- SDA: Connected to A4 pin of Arduino UNO
- SCL: Connected to A5 pin of Arduino UNO
- GND: Connected to GND of Arduino UNO and GND of all MG996R servos
- Vin+: Connected to positive pin of 5V battery
- Vin-: Connected to negative pin of 5V battery
- PWM1: Connected to SIG of MG996R servo (1)
- PWM2: Connected to SIG of MG996R servo (2)
- PWM3: Connected to SIG of MG996R servo (3)
- PWM4: Connected to SIG of MG996R servo (4)
16-Channel PWM Servo Driver (2)
- V+: Connected to positive pin of 5V battery
- VCC: Connected to 5V pin of Arduino UNO
- SDA: Connected to A4 pin of Arduino UNO
- SCL: Connected to A5 pin of Arduino UNO
- GND: Connected to GND of Arduino UNO
MG996R Servo Motor (1)
- GND: Connected to GND of 16-Channel PWM Servo Driver (1)
- VCC: Connected to V+ of 16-Channel PWM Servo Driver (1)
- SIG: Connected to PWM1 of 16-Channel PWM Servo Driver (1)
MG996R Servo Motor (2)
- GND: Connected to GND of 16-Channel PWM Servo Driver (1)
- VCC: Connected to V+ of 16-Channel PWM Servo Driver (1)
- SIG: Connected to PWM2 of 16-Channel PWM Servo Driver (1)
MG996R Servo Motor (3)
- GND: Connected to GND of 16-Channel PWM Servo Driver (1)
- VCC: Connected to V+ of 16-Channel PWM Servo Driver (1)
- SIG: Connected to PWM3 of 16-Channel PWM Servo Driver (1)
MG996R Servo Motor (4)
- GND: Connected to GND of 16-Channel PWM Servo Driver (1)
- VCC: Connected to V+ of 16-Channel PWM Servo Driver (1)
- SIG: Connected to PWM4 of 16-Channel PWM Servo Driver (1)
Arduino UNO
- 5V: Connected to VCC of 16-Channel PWM Servo Driver (2)
- GND: Connected to GND of 16-Channel PWM Servo Driver (2)
- A4: Connected to SDA of 16-Channel PWM Servo Driver (2)
- A5: Connected to SCL of 16-Channel PWM Servo Driver (2)
5V Battery
- positive: Connected to Vin+ of both 16-Channel PWM Servo Drivers
- negative: Connected to Vin- of 16-Channel PWM Servo Driver (1)
Code Documentation
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Initialize PCA9685
Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();
// Servo limits (customize according to your servo type)
#define SERVOMIN 150 // Minimum pulse length (0 degrees)
#define SERVOMAX 600 // Maximum pulse length (180 degrees)
// Setup function
void setup() {
Serial.begin(9600);
Serial.println("Initializing PCA9685");
pca9685.begin();
pca9685.setPWMFreq(50); // Set PWM frequency to ~50Hz for servos
}
// Function to move servo to a position
void moveServo(int servoNum, int pos) {
int pulse = map(pos, 0, 180, SERVOMIN, SERVOMAX); // Map angle to PWM value
pca9685.setPWM(servoNum, 0, pulse);
}
// Loop to create simultaneous movement for 4 servos
void loop() {
// Move 4 servos from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 10) {
moveServo(0, pos); // Servo 0
moveServo(1, 180 - pos); // Servo 1 (reverse direction)
moveServo(2, pos); // Servo 2
moveServo(3, 180 - pos); // Servo 3 (reverse direction)
delay(100);
}
// Move 4 servos from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 10) {
moveServo(0, pos); // Servo 0
moveServo(1, 180 - pos); // Servo 1 (reverse direction)
moveServo(2, pos); // Servo 2
moveServo(3, 180 - pos); // Servo 3 (reverse direction)
delay(100);
}
}
This code initializes the PCA9685 PWM driver and sets up a loop to move four servos simultaneously. The servos are moved from 0 to 180 degrees and then back from 180 to 0 degrees, creating a back-and-forth motion. The moveServo function maps the desired angle to the appropriate PWM pulse length and sends the signal to the specified servo.