Arduino: Controlling the Robot Arm

arduino processing robot arm pt2

So the arm is wired into Arduino as per the previous post, Arduino: Modifying a Robot Arm and hopefully this has worked. In this next part I alter the Arduino sketch slightly and write the first Processing sketch to test control of the arm – video at the bottom.

To control the robot arm we’ll be sending a byte value over the serial port and then reading that in the Arduino code. Depending upon the value sent different motors will be activated.

For the processing sketch I’ve made a few buttons for each motor and also coded the use of the keyboard for another control method. Using either arbitrarily moves the arms motors.

This sketch is the basis for all the further work as well as testing the arm, from this I will move to inverse kinematics as well as programming repeat actions for the arm to perform. Ultimately leading to the arm responding to sensors and other stimuli – eventually! (I have a lot to write up).

For a basic example of working with controlling Arduino using Processing please read my tutorial “Using Processing to Send Values to Arduino” which explains about sending data over the serial port.

The Arduino Sketch
Nothing much has changed from the sketch in the previous post, the main difference is that now you can see we’re reading values from the serial port and acting accordingly. All the logic happens in the Processing code.

/* controls each motor in an Edge Robotic Arm using data sent from 
    a Processing Sketch
// set the output pins
// 14-18 are actually analog pins 0-4
int baseMotorEnablePin = 2;
int baseMotorPin1 = 3;                             
int baseMotorPin2 = 4;                           
int shoulderMotorEnablePin = 14;
int shoulderMotorPin1 = 15;                             
int shoulderMotorPin2 = 16; 
int elbowMotorEnablePin = 8;
int elbowMotorPin1 = 9;                             
int elbowMotorPin2 = 10;                           
int wristMotorEnablePin = 5;
int wristMotorPin1 = 6;                             
int wristMotorPin2 = 7; 
int handMotorEnablePin = 11;
int handMotorPin1 = 17;                             
int handMotorPin2 = 18; 
// set a variable to store the byte sent from the serial port
int incomingByte;

void setup() {
  // set the SN754410 pins as outputs:
  pinMode(baseMotorPin1, OUTPUT);
  pinMode(baseMotorPin2, OUTPUT);
  pinMode(baseMotorEnablePin, OUTPUT);
  digitalWrite(baseMotorEnablePin, HIGH);
  pinMode(shoulderMotorPin1, OUTPUT);
  pinMode(shoulderMotorPin2, OUTPUT);
  pinMode(shoulderMotorEnablePin, OUTPUT);
  digitalWrite(shoulderMotorEnablePin, HIGH);
  pinMode(elbowMotorPin1, OUTPUT);
  pinMode(elbowMotorPin2, OUTPUT);
  pinMode(elbowMotorEnablePin, OUTPUT);
  digitalWrite(elbowMotorEnablePin, HIGH);
  pinMode(wristMotorPin1, OUTPUT);
  pinMode(wristMotorPin2, OUTPUT);
  pinMode(wristMotorEnablePin, OUTPUT);
  digitalWrite(wristMotorEnablePin, HIGH);
  pinMode(handMotorPin1, OUTPUT);
  pinMode(handMotorPin2, OUTPUT);
  pinMode(handMotorEnablePin, OUTPUT);
  digitalWrite(handMotorEnablePin, HIGH);
  // start sending data at 9600 baud rate

void loop() {
  // check that there's something in the serial buffer
  if (Serial.available() > 0) {
    // read the byte and store it in our variable 
    // the byte sent is actually an ascii value
    incomingByte =;
    // note the upper casing of each letter!
    // each letter turns a motor different way.
    if (incomingByte == 'Q') {
    digitalWrite(baseMotorPin1, LOW);   
    digitalWrite(baseMotorPin2, HIGH);  
    if (incomingByte == 'W') {
    digitalWrite(baseMotorPin1, HIGH);   
    digitalWrite(baseMotorPin2, LOW);  
    if (incomingByte == 'E') {
    digitalWrite(shoulderMotorPin1, LOW);   
    digitalWrite(shoulderMotorPin2, HIGH);  
    if (incomingByte == 'R') {
    digitalWrite(shoulderMotorPin1, HIGH);   
    digitalWrite(shoulderMotorPin2, LOW);  
    if (incomingByte == 'A') {
    digitalWrite(elbowMotorPin1, LOW);   
    digitalWrite(elbowMotorPin2, HIGH);  
    if (incomingByte == 'S') {
    digitalWrite(elbowMotorPin1, HIGH);   
    digitalWrite(elbowMotorPin2, LOW);  
    if (incomingByte == 'D') {
    digitalWrite(wristMotorPin1, LOW);   
    digitalWrite(wristMotorPin2, HIGH);  
    if (incomingByte == 'F') {
    digitalWrite(wristMotorPin1, HIGH);   
    digitalWrite(wristMotorPin2, LOW);  
    if (incomingByte == 'Z') {
    digitalWrite(handMotorPin1, LOW);   
    digitalWrite(handMotorPin2, HIGH);  
    if (incomingByte == 'X') {
    digitalWrite(handMotorPin1, HIGH);   
    digitalWrite(handMotorPin2, LOW);  
    // if a O is sent make sure the motors are turned off
    if (incomingByte == 'O') {
    digitalWrite(baseMotorPin1, LOW);   
    digitalWrite(baseMotorPin2, LOW);  
    digitalWrite(shoulderMotorPin1, LOW);   
    digitalWrite(shoulderMotorPin2, LOW); 
    digitalWrite(elbowMotorPin1, LOW);   
    digitalWrite(elbowMotorPin2, LOW);  
    digitalWrite(wristMotorPin1, LOW);   
    digitalWrite(wristMotorPin2, LOW); 
    digitalWrite(handMotorPin1, LOW);   
    digitalWrite(handMotorPin2, LOW); 

[ad#Google Ad in content]

The Processing Sketch
I’ve drawn some fancy arrows for my buttons in this sketch but otherwise the code is pretty simple – if I press Q or q on the keyboard or if I press an arrow button then send the ascii value of Q (note the uppercase) over the serial port for the Arduino to pick up and turn the motor on. There is nothing here really complicated just a fair few lines of code for the user interface.

   Processing sketch that send a ascii byte character to Arduino which
   then subsquentally controls a motor

// load the serial library for Processing
import processing.serial.*; 
// instance of the serial class
Serial port;
// values to store X, Y for each button
int M1LX, M1RX, M2LX, M2RX, M3LX, M3RX, M4LX, M4RX, M5LX, M5RX;
int M1LY, M1RY, M2LY, M2RY, M3LY, M3RY, M4LY, M4RY, M5LY, M5RY;
// stores the width/height of the box
int boxSize = 64;
// 2 new instances of my arrow class
// also set an array of coordinates for each arrow
arrow myRightArrow;
arrow myLeftArrow;
// set the font
PFont myFont;

void setup()  {
  // screen size of the program
  size(145, 455);
  // set the coordinates of each button box
  // base motor M1LX = Motor 1 Left X  etc..
  M1LX = 5;
  M1LY = 25;
  M1RX = 75;
  M1RY = 25;  
  // shoulder motor
  M2LX = 5;
  M2LY = 115;
  M2RX = 75;
  M2RY = 115;
  // elbow motor
  M3LX = 5;
  M3LY = 205;
  M3RX = 75;
  M3RY = 205;
  // wrist motor
  M4LX = 5;
  M4LY = 295;
  M4RX = 75;
  M4RY = 295;
  // hand motor
  M5LX = 5;
  M5LY = 385;
  M5RX = 75;
  M5RY = 385;
  // List all the available serial ports in the output pane. 
  // You will need to choose the port that the Arduino board is 
  // connected to from this list. The first port in the list is 
  // port #0 and the third port in the list is port #2. 
  // set the font to use
  myFont = createFont("verdana", 12);
  // Open the port that the Arduino board is connected to (in this case #0) 
  // Make sure to open the port at the same speed Arduino is using (9600bps)
  port = new Serial(this, Serial.list()[1], 9600); 
  // create the base arrow
  myRightArrow = new arrow(rightArrowxpoints,rightArrowypoints,7);
  myLeftArrow = new arrow(leftArrowxpoints,leftArrowypoints,7);

void draw() 
  // draw each box/ button with a label above each    
  text("Base Motor (Q/W)", 5, 5, 200, 75); 
  text("Shoulder Motor (E/R)", 5, 95, 200, 75);
  text("Elbow Motor (A/S)", 5, 185, 200, 75);
  text("Wrist Motor (D/F)", 5, 275, 200, 75);     
  text("Hand Motor (Z/X)", 5, 365, 200, 75);

  // start looking to see whats pressed and send a value
  // over the serial port
  if(keyPressed) {
    if (key == 'q' || key == 'Q') {
    if (key == 'w' || key == 'W') {
    if (key == 'e' || key == 'E') {
    if (key == 'r' || key == 'R') {
    if (key == 'a' || key == 'A') {
    if (key == 's' || key == 'S') {
    if (key == 'd' || key == 'D') {
    if (key == 'f' || key == 'F') {
    if (key == 'z' || key == 'Z') {
    if (key == 'x' || key == 'X') {
  // if no key is pressed check to see if the mouse button is pressed
  else if (mousePressed == true) {
    // check to see if the mouse is inside each box/ button if so send the value
    if (mouseX > M1LX-boxSize && mouseX < M1LX+boxSize && 
      mouseY > M1LY-boxSize && mouseY < M1LY+boxSize) {
    else if(mouseX > M1RX-boxSize && mouseX < M1RX+boxSize && 
      mouseY > M1RY-boxSize && mouseY < M1RY+boxSize) {
    else if(mouseX > M2LX-boxSize && mouseX < M2LX+boxSize && 
      mouseY > M2LY-boxSize && mouseY < M2LY+boxSize) {
    else if(mouseX > M2RX-boxSize && mouseX < M2RX+boxSize && 
      mouseY > M2RY-boxSize && mouseY < M2RY+boxSize) {
    else if(mouseX > M3LX-boxSize && mouseX < M3LX+boxSize && 
      mouseY > M3LY-boxSize && mouseY < M3LY+boxSize) {
    else if(mouseX > M3RX-boxSize && mouseX < M3RX+boxSize && 
      mouseY > M3RY-boxSize && mouseY < M3RY+boxSize) {
    else if (mouseX > M4LX-boxSize && mouseX < M4LX+boxSize && 
      mouseY > M4LY-boxSize && mouseY < M4LY+boxSize) {
    else if(mouseX > M4RX-boxSize && mouseX < M4RX+boxSize && 
      mouseY > M4RY-boxSize && mouseY < M4RY+boxSize) {
    else if (mouseX > M5LX-boxSize && mouseX < M5LX+boxSize && 
      mouseY > M5LY-boxSize && mouseY < M5LY+boxSize) {
    else if(mouseX > M5RX-boxSize && mouseX < M5RX+boxSize && 
      mouseY > M5RY-boxSize && mouseY < M5RY+boxSize) {
    else {
      // if the mouse is pressed but not with in a box make sure nothings moving
  } else {
    // no key or mouse press then make sure nothings moving.
  // draw the buttons

class arrow extends java.awt.Polygon { 
  /* our class is basically an instance of java.awt.Polygons and this class expects and array of X points, Y points and the number of 
     points in our shape. The variable names also have to be direct references to what this class expects, so xpoints, ypoints and npoints are all
     set/defined in the java class.
  public arrow(int[] xpoints,int[] ypoints, int npoints) {
    // super invokes the java.awt.Polygon class
    // supply offsets to draw the arrow, means I don't need to set points for each one
    void drawArrow(int xOffset, int yOffset){
    rect(xOffset-5, yOffset-5, boxSize, boxSize);
    for(int i=0;i

[ad#Google Ad in content]

Does it work?
Hopefully the sketch is working and you can control the arm via your computer. If not then first check that all motors are wired in properly and your batteries are not flat. If you arrow moves the arm the wrong way then you can either switch the motor pins on the circuit or change the Arduino sketch to alter the motors direction.

Calibrating the arm
We need to set start positions for the arm and note the positions and counts in order to later calculate the positions for the next parts of this work. This is where we'll look to more benefits of Arduino and possibly PID (Proportional, Integral, Derivative) control, PWM or someother way to get accurate positions for the motor. The only catch is each motor is in a gearbox so using an encoder or other device to measure motor rotations is not an option. But for now we can control our arm from the computer at least - check out the video below.

Arduino: Modifying a Robot Arm: How to wire up the robot arm to Arduino.


  • Sweet, I reckon I’ll be picking one of these up this weekend.

    • They’re cheap and you can get one with USB and some software from Maplins but I’ve read reviews and apparently its not that great programmatically. Keep checking back and let me know how you get on if you get an arm – I’ve also got a lot more to write up πŸ™‚

      • I’ve put this project together and finally gotten it to work! Thanks for the great tutorial. Now I’d like to use a wiimote, ala Johnny Lee, to sense the position of the gripper. Do you think that can be fed back to the computer to control the motors? It seems like human propriocention. It feels like it would work if the wiimote has fine enough 3d resolution.

        • Sorry, bit late in getting back to you on this… I reckon you can use the wiimote – never don it myself but I’m guessing you can get some fuzzy 3d data from it, by fuzzy I mean it won’t be accurate since it’ll be fairly erratic data.

          • I can use the wiimote as a sensor for an interactive whiteboard. It is pretty precise in the 2 dimensions of the screen. I can click on small buttons and such. The wiimote is actually a hi res IR camera. Have you seen Johnny Chung Lee’s wiimote projects? they are pretty amazing. I would be surprized if something like what I’m imagining can’t be done. If it works, it would bypass the whole encoder/stepper technology and use a human-like guidance system to contol the motors. If someone could write the controlling software, which I don’t know how to do.

  • your projects are amazing!

  • Awesome project!
    I have an arduino and a store nearby is selling one of these >_>

    I was thinking about incorporating this into one of my uni projects, is this alright with you? (i was reading the copryright rules etc). I will not be using your coder verbatim but I plan on taking some ideas :3 Credit to you will be given of course!

    • Go for it. πŸ™‚

      One thing, I’ve got more work to do on encoding the robot arm movements – you can do a simple counter to measure time taken to move a joint but I’ve found this is very in accurate – I have a solution though but I’ve still to get it working.

  • hi, first of all, thank you for posting your project online with the coding. i just got my arduino in the mail yesterday and i will be getting my arm next week. i wanted to just copy the code and run it to see, but it says
    error: ‘import’ does not name a type In function ‘void setup()’:
    In function ‘void draw()’:
    At global scope:
    sorry if it sounds noobish, iam very new to this. thanks

    • Hey no problem. I post my code to help others or for others to help me πŸ™‚

      OK your errors can be a couple of things, please forgive me for asking dumb questions here but the first code is the Arduino code that gets uploaded to the Arduino board. The second code chunk is for a program called Processing that then controls the Arduino board. So can I assume that you’re already doing this?

      Secondly I’m using Arduino version 0015 so maybe my code is outdated what version of the Arduino IDE/ program and version of Processing are you using?

      If you need help please ask, it takes me ages to find answers sometimes (I’m struggling right now with opamps!).



  • Hi Larry,

    Just wanted to drop by and say thanks for writing up this project, great stuff! I have just started playing with Arduino for the first time and had exactly this in mind (cannibalising the kit arm) for a first project.

    Ultimately I’d like to try and control it physically with accelerometers, probably by interfacing a Wii nunchuk or the new TI ez430 Chronos developers watch. Could make for a cool wearable controller πŸ™‚

    Really look forward to your next installment, keep up the good work!


    • I think I’ve nearly got it sorted to measure the joint movement using some wheel encoders out of an old mouse and if that works out then I might have to look at the Chronos watch πŸ™‚

      • Cool. Just spotted a youtube vid of someone using the watch to control an arm, clever stuff. The watch is pretty neat for only ~Β£30.

  • Excellent work, i’m so glad i stumbled across your amazing blog!
    I recently did a 2-day Arduino workshop, and i’d love to try and build a robot arm.

    Your Arduino projects are brilliant!
    Keep up the good work!

    • Thankyou!

      The good thing about Arduino is it gets you started into Electronics very easily. Now I’m getting in the deeper end and considering a course πŸ™‚

      • Thanks Larry, i finally built my own robot arm, all credit goes to you though.
        Thank you so much for sharing your instructions and code with us.
        I am in awe of your Arduino knowledge πŸ™‚
        Thank you once again!

        • You’re very welcome although please improve on my work! πŸ™‚

  • hey larry, thanks for helping me with my earlier doubt. iam just keen to know, are u still gonna work on the inverse kinematics? i think that would be cool. also i had a doubt, will it be easy to use the accelormeter on my ipod touch to control the robot, would i need to develop an iphone app for that? thanks

    • use iosc

      • Cool, iosc on the iphone?

        • thank you guys, i used touchosc and now i can control the robot with my ipod touch. Its pretty cool..

          • Cool. Definitely cool. I’m going to build an arm from scratch but I hope to get to using something like an iPod or phone to control it.

  • hi larry…
    nice job… i am building my first robotic arm… your work will help me a lot… i have few queries though… first why arent u using a servo motor as arduino have library for it… and what changes should i make in the code if a intend to use a servo motor..

    • I would love to use servos Rohan! Trouible is the robot arm kit I had uses motors in their own gearboxes and it seemed like less work to stick with the motors.

      With servos it would be awesome since you don’t have to worry about encoding the position of each servo – something I’m currently trying to do, which I think Ive figured out.

      If you were to use servos, you would have to add the library to Arduino, you wouldn’t need the H-bridge chips just 5 pins, 1 for each servo and the power and gnd connections for each. If you’re using larger servos greater than 5 volts or a 40 mA draw you would need to use a separate power supply and use some transistors -TIP120’s or something.

      Code wise not much would be needed to be modified, just for each key press you would rotate a servo using PWM instead – I’ve done some servo work here:

      If anyone knows of a cheap(ish) arm with servos let me know!

      • hi larry,
        can you please suggest me some online tutorial for inverse kinematics… i need to study it from the scratch… i want to build a robotic arm that will orient its joints itself so as to reach the final position…

        • Hi Rohan,

          You will need some servos to do this which Arduino can control very easily. Depending on how many joints you want but start with 2.

          To control them you’ll want to use something like for which you can use the librarys to control the servo position.

          For Inverse Kinematics to work you need to be able to accurately measure the degrees of movement in each joint – hence Servos, although you can can do stepper motors and the rotary encoder route but why bother.

          I will write an IK tutorial up that shows how to calculate the angles very easily in Processing – its not a ‘true’ way to do IK but the end result is the same and the trigonmetry is easier to understand. I can also write up a brief traditional tutorial on IK too.

          I was looking at getting 5 servos and an arm kit myself to do this so if you find any cheap enough let me know.


          • Looking forward to seeing that Larry πŸ™‚

            I finished my arm, thanks for your guide. Interfaced it with the accelerometers in the Chronos watch too, works nicely! Will try and get a video up soon.


          • sweet! look forward to seeing the video. So how does your acceloremeter move the arm – does it just do a different motor depending on the movement?

          • Yeah, a simple processing sketch requests the acc data via a serial com port (the USB receiver MCU). The watch then sends back 7 bytes of info, whihch includes button presses & XYZ values. Very straightforward.

            At the moment I have coded it simply, so that a change in one axis above or below a threshold results in the corresponding motor activation (by passing an ASCII value to the arduino as per your sketch). What would be nice is to code it so that the last acc value is stored and then compared to the current value, so that the motors could respond immediately to movement (rather than having to move your arm all the way down or all the way up to activate the corresponding motor).

            I am also playing with RoboRealm (image processing software) at the moment too, eventually Id’d like to bolt a webcam to the arm and have it identify tarkets and track movement. Definitely getting into servo’s there tho!

          • Hi Larry

            I’ve just built my USB version of the robot arm and the supplied software is terrible. I’ll bin it and use your Arduino version instead ASAP.

            I’m very interested in your rotary encoder and IK solutions. Any news on your next installment?



          • Hi Fergal,

            Its awful – basically it does what I was going to try to program but found it to be useless and inaccurate.

            I’ve just invested in some tools to modify the arm so I can attach encoders to the motors, also I’m looking at building an arm from scratch using servos instead

  • just made it

  • Hi Larry – excellent project. I found the procontrol library and adapted your code to use a PC joystick – I must I’m very impressed with the whole thing. The Arduino is a very nice platform.

    Thanks for posting it


    • Hi Dave,

      My only gripe with the arm is the lack of control, or rather repeated control and precision.

      I’m working on building an arm from scratch, for about the same cost, which should make programming it easier (I hope).

      Did you have a link to your project?



  • sir gud evening to you…i would like to ask if the pinsir of the robotic arm is also moving?…or picking anything…I am amazed about your work and i just stumbled looking for sumthing for a proposal of ours in school…just got lucky though because my proposal is ol about robotic arm en i really dont know if it is coinccident or not because the robot that you actually modified is also the thing that me and my group will purchase later this month….i do also have a arduino duemilanove (in hand)….do you actually have ol the details (here) how you made this brilliant projects of yours?…thank you^_^

    • Hi there,

      All the details should be written up – the pinsor is not moving, simply because I run out of pins on the Arduino to control the motor – what you need to look at (and so do I) are shift registers that allow multiple ICs to be controlled by 1 Arduino pin instead of many of them. I’ll try to write something up to explain this in detail.

  • […] […]

  • Hi,

    Awesome project – my son and I built it in an hour!

    Do you have the processing code in pde downloadable? I am missing the last section?
    Cut and paste is not working…

    Many Thanks

    • Hey sorry bout that (and the delay in fixing this). looks like it got truncated sometime ago. anyway it’s all fixed now.

  • Hey Larry,

    I am receiving the Robotic Arm Kit with USB PC Interface as a present for Christmas and have been blown away with your tutorials and ideas. Forgive me for being somewhat new to this sort of thing (the mechatronic side of things anyway) but I have a few questions:

    As there is a built in usb interface in the version of the robot arm that I am getting – is there still a need for the Arduino module? My reason is that if the arm is already being controlled by the built in software – why do we need to use Arduino?

    My second question is rather basic – what is the programming language (or program even) that you use to control the robot arm? If it is (as I believe) β€œProcessing” for Arduino, and if Arduino is not needed as the inbuilt software controls the arm, what other software if any can I use. It looks like I need to write DLL’s to control the arm – so what should I write these in?

    The reason being: I am producing a chaos experiment using a coupled oscillator and I basically need initial starting conditions to be as precise as possible – which is where the robot arm comes in. However, I have read that the software that comes with the arm is somewhat skittish and hence not ideal for the control I need?

    Many apologies if these questions are too simplistic and many thanks in advance for youre time.

    Best Regards


    • Hey, hope you got the robot arm for Christmas.

      Since you have a USB interface then things are probably a bit easier and you don’t need the Arduino. I had no USB so that’s really why I used it. I’ve seen the software that it comes with and it has the same problems that I found, in that you can’t accurately reproduce or program a set of movements due to the motors and there being no measurement on degrees of rotation on these motors.

      Now I reckon you can control the arm using any programming language you want as long as it can send a signal via the USB and understand a response. If it’s DLL’s then I guess you hould really write in C / C++ in any Windows compiler.

      But going back to my previous point the software isn’t the whole cause of it being skittish – the only way you can control these motors is by counting the time lapsed in a signal sent, e.g. activate motor for x seconds will move the arm about x degrees. When what you really need are servos or stepper motors that have precise feedback loops that let you specify a degree of rotation.

      I did look at modifying this arm to build in rotational encoders so degrees could be measured on each joint but it proves somewhat difficult due to all the plastic casing.

  • i need yo help good Larry
    you code is incomplete after “FOR”
    for(int i=0;i………………..

  • Hey, I’m a good programmer, but I’ve never messed with electronics in this way. I’m looking for a programmable robotic arm just like this that I can control in Java or C++. Would you be willing to sell me one that you made? Contact me at erikcorona AT

    • Well even better you can make a prototype with a few servos. πŸ™‚

  • i need yo help for theProcessing sketch robotarm,i have a arduino mega 2560.
    nothing works mouse en buttons,motor test with h-bridge is ok .
    loading the sketch RX is continue on.
    can you help me please

    Best Regards

    Bram uit holland

    • if the RX is on, it would suggest that it’s an issue with your USB, you can’t run the Arduino software and processing at the same time. Might check that my code compiles without error on the 2560. Also could be the USB port assignment perhaps.

      • larry
        thanks voor response, i tried with een arduino uno and it works perfect.
        the mega 2560 do not like processing there are more program that wil not working with it.
        next step is the robot arm with xbee and the iphone, have you an idee to fix this.

        Best Regards

        Bram uit holland

  • Wow, this is the best tutorial i’ve seen in a long time. Easy to follow, and it works so well! I’ve just been playing around with the Arduino for a month or so, getting to grips with programming. I bought the Edge robot arm thinking it would be fun to hack and this site has really helped me a great deal in getting it working. The results are better than I expected, considering the Edge kit is basically a toy, using cheap motors with a worm drive gear box etc, of course it’s not going to be that accurate. The code and processing sketch I’m impressed with as it works so flawlessly, I’m hoping to see that Inverse kinematics tutorial, that would be awesome!! At last my Arduino is getting some decent use other than flashing LED’s on and off! Nice one Larry!

  • Hi Larry,

    I modified arm. And write now when i am running code in processing sketch.
    it shows arrayindexoutofboundsexception error on line of
    ” port = new Serial(this, Serial.list()[1], 9600); ”

    I also get nullpointexception on pressing on on arrow .

    Will you please help me in this.

  • thx man my mod robot πŸ˜€
    pc iphone

  • hey,

    This tutorial looks great so i thought id give it a go to help me understand the arduino a little better. I have managed the whole of stage one, from building the arm to then hacking it and placing all the wires into the correct places on the breadboard and the arduino (duemilanova in my case).

    I then run into problems when it comes to second stage…I copied the code across for the arduino into the arduino program verified and then uploaded it to the arduino, without issue. I then close the arduino program and open up processing…I copy across your code into processing and run it opens a small java window with the arrows…when i click nothing happens and the arrows are all in grey…what am i doing wrong?

    Hope u can help



    • Just to add…I get this message at the bottom of the processing screen:

      Warning: RXTX version mismatch

      jar version = RXTX-2.2pre1
      native lib version = RXTX2.2pre2

      [0] “/dev/tty.usbserial-A4009RAO
      [1] “/dev/cu.usbserial-a4009rao
      [2] “/dev/tty.bluetooth-PDA-sync”
      [3] “/dev/cu.bluetooth-PDA-sync”
      [4] “/dev/tty.bluetooth-modem”
      [5] “/dev/cu.bluetooth-modem”

  • Thanks for the great writeup. I have the arm working with the H bridges but have some problems with the processing sketch. When i try to run it i get:

    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2
    [0] "COM3"
    Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1
    at sketch_nov07a.setup(
    at processing.core.PApplet.handleDraw(Unknown Source)
    at Source)

    processing jumps to this line and halts:

    // Open the port that the Arduino board is connected to (in this case #0)
    // Make sure to open the port at the same speed Arduino is using (9600bps)
    port = new Serial(this, Serial.list()[1], 9600); <------- that line

    when i change [1] to [3] ( my serial port ) i get:

    ArrayIndexOutOfBoundsException: 3

    when i comment the line out the java loads and i get a grey screen without buttons.

    Any help would be greatly appreciated.

    • That’ll be because there is no 4th item in the array – your third item in the array will actually be [2] as arrays start at 0.

      • Hi Larry,

        Thanks for the reply. As far of what you are telling about the array, its like Chinese to me (and my Chinese is bad). Maybe you can help me with the code ? I’ve copyed your code and i get the error. What do i have to change.

        Thnx in advance,



  • Hi Larry, im new to this kinda thing, i bought the robot arm a couple of weeks ago, with the intention of to do menial tasks (turn on the tv, answer the phone, etc) and i built it, but i dont know how to program it, i understand the electronic aspect, but i just dont get any part of programming. Is their any chance that you could just tell me the basics. πŸ™‚

    • The biggest problem you’ll face will be repeatable results – the arm has no way of knowing what position it’s at so varies each time you try and set it.

      There are a few hacks out there that let you do fix this, which you’ll need to look into if you want it to do tasks (I really should write my own hack up)

      • Have you seen my post about using a Wiimote to sense the arm’s position and feedback to the computer to determine how to move it? It seems to my non-programmer’s mind that it should work. I know it works really well with the Interactive Whiteboard I built based on Johnny Chung Lee’s Wiimote setup.

  • Hi Larry,

    IΒ΄m with the same problem of mrrepel. I try to play the program in processing and there is an error:

    Exception in thread “Animation Thread”
    java.lang.ArrayIndexOutOfBoundsException: 1

    What is the problem?

  • HI Larry,

    Great stuff you have it here, posted on your blog!! Thanks for publishing this!
    I have the ROBOTIC ARM EDGE and I did the upgrade using the Arduino, but it didnt work.
    I only did the first part, controlling by the keyboard.
    The program is fine, since it didnt show any ‘error message’. The compilation went fine. But when I press the keys doesnt do anything.
    All the wiring connections are fine as well, because I did a much simpler program controlling the arm by time ( few sec to left, few sec to the right) and all the motors worked.
    Any idea of what went wrong? Could it be the fact that I used L293D instead of the SN754410?
    Thanks anyway.
    Keep up the good work!

  • Have you ever considered using a Wiimote to sense the position of the gripper and feedback to the computer to move it to any 3D position it can reach? I’ve built Johnny Chung Lee’s Wiimote Interactive Whiteboard for my classroom, and it seems this technology could work if it can resolve locations with sufficient precision. All you would need is to replace the led with an IR led and possibly aim it upwards instead of forward. What do you think? It’s way beyond my non-existent programming skills to do that, but it seems like it would be basically a software problem rather than a hardware one.

  • Did I do something wrong? I posted here 2 days ago about using a Wiimote to control the Edge arm. It showed up right away, then disappeared the next time I looked for a reply.

    • OOPS! It seems to still be here. I don’t know why I couldn’t find it.

  • Why can I only see my previous posts if I post again? I can find no way to advance pages here. Is it my Chrome browser?

  • sir i m getting this error while run the program in processing,
    [0] “COM1”
    Exception in thread “Animation Thread” java.lang.ArrayIndexOutOfBoundsException: 1
    at sketch_jan01a.setup(
    at processing.core.PApplet.handleDraw(Unknown Source)
    at Source)

  • hey πŸ™‚ ..can u tell me how to move the arm to a particular position and to a particular angle??

    • you’d need inverse kinematics and better control over the motors e.g. you need to measure degrees of rotation accurately

You must be logged in to post a comment.