Robotic Arm Basics

Building a Simple Robotic Arm

Learn to build and control a robotic arm using servo motors!

Components Needed

  • Arduino Uno
  • 3× Servo Motors (SG90)
  • Robotic arm kit or DIY materials
  • External 5V power supply
  • Breadboard and jumper wires

3-Axis Robotic Arm Code


#include 

Servo baseServo;    // Base rotation
Servo shoulderServo; // Shoulder up/down
Servo gripperServo;  // Gripper open/close

void setup() {
  baseServo.attach(9);
  shoulderServo.attach(10);
  gripperServo.attach(11);

  Serial.begin(9600);
  Serial.println("Robotic Arm Ready!");

  // Initialize to home position
  homePosition();
}

void loop() {
  // Demonstration sequence
  pickAndPlace();
  delay(3000);
}

void homePosition() {
  baseServo.write(90);
  shoulderServo.write(90);
  gripperServo.write(90);
  delay(1000);
}

void pickAndPlace() {
  // Move to pick position
  baseServo.write(45);
  delay(500);
  shoulderServo.write(120);
  delay(500);

  // Close gripper to grab
  gripperServo.write(60);
  delay(500);

  // Lift object
  shoulderServo.write(60);
  delay(500);

  // Rotate to drop position
  baseServo.write(135);
  delay(500);

  // Lower object
  shoulderServo.write(120);
  delay(500);

  // Release gripper
  gripperServo.write(90);
  delay(500);

  // Return to home
  homePosition();
}
      

Joystick Control

Add a joystick for manual control:


const int joyX = A0;  // Base rotation
const int joyY = A1;  // Shoulder movement

void loop() {
  int xValue = analogRead(joyX);
  int yValue = analogRead(joyY);

  // Map joystick values to servo angles
  int baseAngle = map(xValue, 0, 1023, 0, 180);
  int shoulderAngle = map(yValue, 0, 1023, 0, 180);

  baseServo.write(baseAngle);
  shoulderServo.write(shoulderAngle);

  delay(15);
}
      

Assembly Tips

  • Use external 5V power for servos (Arduino 5V pin can't supply enough current for 3 servos)
  • Connect all GNDs together (Arduino + Servo power supply)
  • Secure servos firmly to prevent wobbling
  • Add counterweights if arm is unbalanced

ℹ️ Info: Advanced: Add inverse kinematics for precise XYZ coordinate control!