Arduino Uno Controlled 6-Servo Robot Arm with 3 Analog Joysticks
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a robot arm with 6 servos using 3 analog joysticks. The system is powered by a 5V 5A power supply and is controlled by an Arduino Uno R3 microcontroller. Each joystick controls two servos: one for the vertical axis and one for the horizontal axis.
Component List
Arduino Uno R3
- Description: Microcontroller board based on the ATmega328P.
- Pins: D8, D9, D10, D11, D12, D13, GND, AREF, SDA, SCL, D0/RX, D1/Tx, D2, D3, D4, D5, 6, D7, A5/SCL, A4/SDA, A3, A2, A1, A0, Vin, 5V, 3.3V, RESET, IOREF, NONE, USB Jack, Power Jack.
MG996R Servo Motor
- Description: High-torque digital servo motor.
- Pins: GND, VCC, SIG.
Analog Joystick
- Description: Analog joystick module with two potentiometers and a push button.
- Pins: VCC, VERT, HORZ, SEL, GND.
POWER SUPPLY 5V 5AMP
- Description: Power supply providing 5V DC at 5A.
- Pins: 220V Positive Pole (AC), 220V Negative Pole (AC), GND, GND (DC), 12V-24V Output (DC).
Wiring Details
Arduino Uno R3
- GND: Connected to GND of all MG996R servos and Analog Joysticks.
- D2: Connected to SIG of MG996R Servo 1.
- D3: Connected to SIG of MG996R Servo 2.
- D4: Connected to SIG of MG996R Servo 3.
- D5: Connected to SIG of MG996R Servo 4.
- 6: Connected to SIG of MG996R Servo 5.
- D7: Connected to SIG of MG996R Servo 6.
- A5/SCL: Connected to HORZ of Analog Joystick 1.
- A4/SDA: Connected to VERT of Analog Joystick 1.
- A3: Connected to HORZ of Analog Joystick 2.
- A2: Connected to VERT of Analog Joystick 2.
- A1: Connected to HORZ of Analog Joystick 3.
- A0: Connected to VERT of Analog Joystick 3.
- 5V: Connected to VCC of all Analog Joysticks.
MG996R Servo Motors
- GND: Connected to GND of Arduino Uno R3 and Power Supply.
- VCC: Connected to 5V output of Power Supply.
- SIG: Connected to respective digital pins on Arduino Uno R3 (D2, D3, D4, D5, 6, D7).
Analog Joysticks
- GND: Connected to GND of Arduino Uno R3.
- VCC: Connected to 5V of Arduino Uno R3.
- HORZ: Connected to respective analog pins on Arduino Uno R3 (A5/SCL, A3, A1).
- VERT: Connected to respective analog pins on Arduino Uno R3 (A4/SDA, A2, A0).
POWER SUPPLY 5V 5AMP
- 220V Positive Pole (AC): Connected to AC mains.
- 220V Negative Pole (AC): Connected to AC mains.
- GND: Connected to GND of Arduino Uno R3 and all MG996R servos.
- 5V Output (DC): Connected to VCC of all MG996R servos.
Code Documentation
/*
* Robot Arm with 6 Servos and 3 Joysticks
*
* This code controls a robot arm with 6 servos using 3 analog joysticks.
* Each joystick controls two servos: one for the vertical axis and one for
* the horizontal axis.
*/
#include <Servo.h>
// Define servo objects
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
// Define joystick pins
const int joy1Vert = A0;
const int joy1Horz = A1;
const int joy2Vert = A2;
const int joy2Horz = A3;
const int joy3Vert = A4;
const int joy3Horz = A5;
// Define servo pins
const int servo1Pin = 2;
const int servo2Pin = 3;
const int servo3Pin = 4;
const int servo4Pin = 5;
const int servo5Pin = 6;
const int servo6Pin = 7;
void setup() {
// Attach servos to pins
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);
servo5.attach(servo5Pin);
servo6.attach(servo6Pin);
}
void loop() {
// Read joystick values
int joy1VertVal = analogRead(joy1Vert);
int joy1HorzVal = analogRead(joy1Horz);
int joy2VertVal = analogRead(joy2Vert);
int joy2HorzVal = analogRead(joy2Horz);
int joy3VertVal = analogRead(joy3Vert);
int joy3HorzVal = analogRead(joy3Horz);
// Map joystick values to servo angles
int servo1Angle = map(joy1VertVal, 0, 1023, 0, 180);
int servo2Angle = map(joy1HorzVal, 0, 1023, 0, 180);
int servo3Angle = map(joy2VertVal, 0, 1023, 0, 180);
int servo4Angle = map(joy2HorzVal, 0, 1023, 0, 180);
int servo5Angle = map(joy3VertVal, 0, 1023, 0, 180);
int servo6Angle = map(joy3HorzVal, 0, 1023, 0, 180);
// Write angles to servos
servo1.write(servo1Angle);
servo2.write(servo2Angle);
servo3.write(servo3Angle);
servo4.write(servo4Angle);
servo5.write(servo5Angle);
servo6.write(servo6Angle);
// Small delay to allow servos to move
delay(15);
}
This code initializes six servo objects and assigns them to specific pins on the Arduino Uno R3. It reads the analog values from the three joysticks and maps these values to servo angles, which are then written to the servos to control their positions. The loop continuously updates the servo positions based on the joystick inputs.