Need help with programming a robotic arm with a minimum of 3 servos

Hi guys, I need help programming a robotic arm. The arm is a Robix kit that contains 6 servos, but if i can get 3 servos working, it is good enough. I also want to control it with a ps2 analouge controller. So far i need a robotic arm that can turn left/right up/down and activate a pincher. Any help will be great 8)

I am a noob btw, and i need it for a school project :grin:

Would be glad to help but could you please give us a link to the kit.

Also, what Arduino are you using.

Btw once the first servo is working the other 5 will be easy!

Thanks for showing interest :slight_smile:

The link : Contents of the Robix Rascal Robot Construction Set

I am also using an Ardiuno uno, i got like a couple days ago

Can I use the Bill Porter schematic for hookin up my ps2 analouge controller?

To be honest I don’t know how to use the ps2 controller but I can show you how to move your servos.

To control a servo you will need to use all three wires coming from it. The yellow one should be connected to a pwm pin on your Arduino. The black wire is ground and the red is live. You will need a 5v power supply. If you try to pull power from you Arduino you will destroy it. A battery pack or a wall wort should do the trick. Simply put the positive wire from the power source to the positive wire of your servo. Do the same with the ground wire.

Try just one servo to start with and use the code below. Once you get it working try to adapt the program to control 6 servos if you can’t I will show you how.

#include <Servo.h> 
Servo myservo

void setup() 

  myservo.attach(9); // plug the servo into pin 9

void loop() 




Also, make sure the servo you use is not connected to the arm!

If you can give me the link to the controller and the receiver I will look at them and see if I can figure out how to program it.

I was actually planning to do the cheapest way possible without a transmitter and a receiver. A direct link with the controller and arduino, and then the arduino to the servo(s)

This video helped me a little, but i still need to control it with a ps2 controller.

The trial run with one servo was successful, thank you :)

I get it now. That is much easier to program then if it was wireless. It so cool… I want one :)

From what I can see you will need 5 servos and 5 buttons.

  1. up
  2. down
  3. left
  4. right
  5. pincher.

What buttons on the controller do you want to use for those motions. I was thinking the group of buttons on the left of the controller for motion and maybe one of the ones on the back side to activate the pinch?

Chose which one you want and we can start programing. Also do you have any experience in C?

I have absolutely no experience in C, I am a junior in high school and I am just starting off :blush:. Ive seen a couple of tutorials on youtube but none really help me out. Although I have no experience this field really intrigues me and sheer amount of things one can create with an arduino. :grin:

I'm also in high school, but have been at this for a while.

Do you know what buttons you want to use?

I have found this book to be an awesome help…

Look into the robofest competition thats what got me started!

im good with using the left pad to control movement, and the bumpers on the back of the joystick for the pincher :) Thank you so much guys :sweat_smile:

I have 2 midterm tests this week so I don't know if I will be able to wright up an example for you this week. Unless somebody gets to it faster I should have something during spring break (next week).

ok man, anything is greatly appreciated :D

Search the forums for posts by Zoomkat - his test code for servos should get you started with one axis and once you have that it should be easy enough to add others.

I have the code mostly working. Could you send me a picture of how you built your robot. It depends how I finish up the code.

Also I have added lots of comments so you can understand how it works. That way you can explain everything if your teacher asks!

Some times I can't get pictures to load on the forum. If thats the case IM me and I will give you my email.

You don't normally need two servos for "up" and "down". One servo will move the arm in both directions.

Not if you want the up and down to have two points of motion. This Arm has six servos so I assume their is more then one servo controlling up and down.

Some servo test code for more than one servo.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c =;  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
          Serial.print("writing Microseconds: ");
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
          Serial.print("writing Angle: ");
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
         readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString