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

Arduino UNO-Based Multi-Servo Robotic Arm Controlled by Joysticks

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Multi-Servo Robotic Arm Controlled by Joysticks

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller interfacing with multiple servos and joystick modules. The Arduino UNO reads analog signals from the joysticks and controls the servos based on these inputs. Additionally, the circuit includes a 5V power connector to supply power to the components.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Servo (x7)

    • Description: A servo motor used for precise control of angular position.
    • Pins: gnd, vcc, pulse
  3. KY-023 Dual Axis Joystick Module (x3)

    • Description: A joystick module that provides analog output for X and Y axes and a digital output for the switch.
    • Pins: GND, +5V, VRx, VRy, SW
  4. Connector 5V

    • Description: A connector to supply 5V power to the circuit.
    • Pins: GND, VCC

Wiring Details

Arduino UNO

Servo 1

Servo 2

Servo 3

Servo 4

Servo 5

Servo 6

Joystick 1

Joystick 2

Joystick 3

Connector 5V

Code Documentation

#include <Servo.h>

// Declaration of servo objects
Servo servo_0, servo_1, servo_2, servo_3, servo_4, servo_5, servo_6;

// Joystick analog pins
const int joystick1_x = A0, joystick1_y = A1;
const int joystick2_x = A2, joystick2_y = A3;
const int joystick3_x = A4, joystick3_y = A5;

// Switch pins
const int switchPin1 = 9; // Switch for joystick 1
const int switchPin2 = 10; // Switch for joystick 2
const int switchPin3 = 11; // Switch for joystick 3

void setup() {
  Serial.begin(9600); // Initialize serial communication

  // Initialize switch pins as input with internal pull-up resistors
  pinMode(switchPin1, INPUT_PULLUP);
  pinMode(switchPin2, INPUT_PULLUP);
  pinMode(switchPin3, INPUT_PULLUP);

  // Attach servos to pins
  servo_0.attach(2);
  servo_1.attach(3);
  servo_2.attach(4);
  servo_3.attach(5);
  servo_4.attach(6);
  servo_5.attach(7);
  servo_6.attach(8);
}

void loop() {
  // Handle joystick control
  handleJoystickControl();

  // Handle serial input
  if (Serial.available() > 0) {
    handleSerialInput();
  }

  // Small delay to avoid overwhelming the servos
  delay(20);
}

void handleJoystickControl() {
  // Read the switch states
  bool switchState1 = digitalRead(switchPin1) == LOW;
  bool switchState2 = digitalRead(switchPin2) == LOW;
  bool switchState3 = digitalRead(switchPin3) == LOW;

  if (switchState1) {
    // Read joystick 1 values and control servo_0 and servo_1
    int servo_0_pos = map(analogRead(joystick1_x), 0, 1023, 0, 180);
    int servo_1_pos = map(analogRead(joystick1_y), 0, 1023, 0, 180);
    servo_0.write(servo_0_pos);
    servo_1.write(servo_1_pos);
  }

  if (switchState2) {
    // Read joystick 2 values and control servo_2 and servo_3
    int servo_2_pos = map(analogRead(joystick2_x), 0, 1023, 0, 180);
    int servo_3_pos = map(analogRead(joystick2_y), 0, 1023, 0, 180);
    servo_2.write(servo_2_pos);
    servo_3.write(servo_3_pos);
  }

  if (switchState3) {
    // Read joystick 3 values and control servo_4, servo_5, and servo_6
    int servo_4_pos = map(analogRead(joystick3_x), 0, 1023, 0, 180);
    int servo_5_pos = map(analogRead(joystick3_y), 0, 1023, 0, 180);
    int servo_6_pos = 180 - servo_4_pos; // Synchronize servo_6 with servo_4
    servo_4.write(servo_4_pos);
    servo_5.write(servo_5_pos);
    servo_6.write(servo_6_pos);
  }
}

void handleSerialInput() {
  // Read the data string from the serial input
  String input = Serial.readStringUntil('\n');
  int servoIndex = input.substring(0, 1).toInt(); // Get the servo index
  int servoValue = input.substring(2).toInt(); // Get the servo value

  // Write the value to the corresponding servo
  switch (servoIndex) {
    case 1:
      servo_0