Posts

Controlling robotic arm with Arduino and USB mouse

Many people asked me to post a video showing an arm from inverse kinematics article in action. While making a video, I realized that shots of the arm following a pattern of computer-generated coordinates is going to be less than exciting and decided to add manual control. The video below shows the result. In addition to the video, a HID introductory page has been written describing HID communication basics as well as some simple Arduino code. Enjoy! ( Youtube link, where HD quality video can be selected ).

Arduino sketch written for this video is on gitHub.

110 comments to Controlling robotic arm with Arduino and USB mouse

  • GeorgeFlacker

    This is so Awesome. Thank you for posting and give inspiration to all geeks in the world!

    God Bless.

  • sattar

    i must appreciate ur work. arm design is perfect.use of usb wid arduino peripheral really catches my attention. clapping from my side for this dedicated work.

  • vineel

    making an arm with arduino and usb mouse is very complex but u have done it.
    thanks for your creativity..

  • karan

    have done the 30 degree up when assembling the arm for elbow as given inn lynxmotion assembly guide ?

  • varghese

    that was brilliant work……i am just a beginner can u please send me the schematic along with the components needed to make this arm……please

  • sara

    this project is very intresting..i am just biginner in this field and i need your help,can u please send me the schematic and what components that should have to do this project?

  • Asif

    Hello oleg, great work man, i saw the video, oleg can you please help me out for some alternative of renbotics sheild, would you suggest some other way to drive servo motors if i am not available with all the pwm pins of arduino.
    Thanks oleg, waiting for your reply

    • Hi,

      Anything capable of driving 6 servos would work. Renbotics shield is very simple – you can buld one yourself (that’s what I did). Take a look at their site for schematic.

      • asif

        yes oleg you are right but i just noticed in video of this arm that motors aren’t moving smoothly, is that due to renbotics shield or something else?
        Thanks for the reply oleg, i want to know if i can get something more with renbotics shield to operate motors in more smoother way, is that possible?

        • Servos are moving smoothly, the arm is spring-loaded – as a result, arm movement is jerky at times.

        • asif

          okay oleg, i got it, thanx alot for guiding 🙂

          • asif

            oleg one more thing i want to ask, there’s a big capacitor you are using in renbotics servo shield, that is not mentioned in its schematic, which capacitor is that the one in blue color?

  • Omer

    Hey oleg!
    This is really a Brilliant work and i think its the first do it your self guide on implementing inverse kinematics so easily. I have been looking for such a thing for months now. I am kind of a PIC guy and really new to arduino(thanks to you for making me a big fan of arduino).Can you please guide me how can we control the arm using a keypad and lcd. I mean so that we can enter the coordinates and the arm works according to it. And if its possible please tell me where to change the code for it.

    Regards
    Omer

  • asif

    oleg one more thing i want to ask, the capacitor you are using in renbotics servoshield, the one in blue color, that is not mentioned in schematics of it, what value of capacitor is that and what are its connection with the shield, thanks for the prevoius replies, they were helpful.

    • Just some big electrolytic cap, like several thousands microfarad rated at ~1.5 times servo voltage. Don’t sweat it – I put it there because I had it, servos will work just as well without it.

      • asif

        hey oleg,
        i wanted to ask one more thing, you have connected the 14th and 15th pin of 4017 ic with 5th adnd 6th pin of arduino, is that so? in schematics of renbotics its connected with pin number 6th and 7th of arduino, is there some change in codde as well for that?
        thanks oleg for prevoius help

  • asif

    you mean to say that current version of renbotics shield does not use pin 7 of arduino?
    can you please elaborate me more that pin 14th and 15th of 4017 ic are connected with which pins of arduino for the revised version, i am using usb host shield with that as well.
    Thanks oleg

    • I meant to say that new version of USB Host Shield doesn’t use pin 7. The rest of the conections is by default and I don’t use second 4017.

  • asif

    okay oleg, thanks alot for the help 🙂

  • asif

    sorry oleg i am asking you again and again about small things, actually i am working on it as my final semester projet, and that is why needing your help again and again,
    oleg i first implemented the sketch for the communication of mouse with arduino that you’ve given in the respective topis, my mouse is working with the INTERRUPT’s sketch not with the ‘Get report’ one, now what changes would i’ve to made in the overall sketch to implement this project using the ‘INTERRUPT’ sketch, i tried combining the both sketches and made some more editions in that but its still not working with mouse, can you help me a bit more about it,
    Thanks oleg you already helped alot

  • Asif

    hey oleg, i want to know few things about the code, can you please help me out about the code of this project, how did you decide that how much should the motor upon the change of several coordinates during movement of mouse?
    how these -0.1 and and -2 you decided for this, i am confused about this
    armdata.x_coord += ( buf[ 1 ] * -0.1 );
    armdata.y_coord += ( buf[ 2 ] * -0.1 );
    switch( buf[ 0 ] ) { //read buttons
    case 0x00: //no buttons pressed
    armdata.z_coord += ( buf[ 3 ] * -2 ) ;
    break;
    case 0x01: //button 1 pressed. Wheel sets gripper angle
    armdata.gripper_servo += ( buf[ 3 ] * -20 );
    /* check gripper boundaries */

    • -0.1 and -2 is the scale. X and Y are about 600 dpi, so I divide it by 10 and also invert direction. X is coarse, like 6 clicks per revolution, so I multiply it by 2 and also invert direction.

  • Asif

    waiting for your reply…thanks

  • scc

    Asif:
    Im working in a proyect like you. Can you help me with some doubt? my mail is sacalleja@miuandes.cl.

    regards

  • scc

    ok no problem! a teacher from my university saw you project and ask me do this. Is my last course of the career. i don´t have any idea how to start a code to control the arm by mouse. i never have worked whit this before and i dont know much about robotics. what should be my first step?

    Thanks oyu

    • if you need to write this code from scratch I suggest learning about inverse kinematics – there are links in the article as well as plenty of info elsewhere on the net.

  • taipscode

    Hello Mr Oleg.
    I think ,you are a hard man.
    It’s difficult to received from your help.
    Can you help me get coordinate X,Y by arduino mega adk with usb mouse such as : http://www.martijnthe.nl/2009/07/interfacing-an-optical-mouse-sensor-to-your-arduino/

    Because i don’t want to cut wire of usb optical mouse.
    Please ,help me Mr Oleg.

  • taipscode

    Hello ,Mr Oleg.
    I want to buy code of usb mouse.
    Can you give me price and account to send money?
    Thanks

  • scc

    Mr Oleg: Im looking to buy a USB Host Shield. I saw the USB host shield from Sparkfun, Do you think is it an appropriate USB Host Shield, for this project? What USB shield did you use?

    Regards

  • scc

    Mr Oleg: The products can be send to Chile? maybe via fedex?

    Regards

  • taipscode

    Hello Mr Oleg .
    It’s error Max3421.cpp.
    I download it from wesite and add to arduino library ,but don’t accept.

    Can you give me Max3421.cpp
    Thanks

  • taipscode

    Mr Oleg just died,hic hic…

  • taipscode

    Hello Mr Oleg
    I uploaded UsbHdiBootMouse.pde to Arduino mega ADK successfully.
    But result is OSC did not start.
    https://picasaweb.google.com/lh/photo/7I47IKurycWwhhu0sJtloqSrQy2kQI_kUU0h-UhI77Y?full-exif=true

    Can you tell me about the name of mouse in your video clip.
    Thanks a lot.

  • Brendan F

    Hey this is a fantastic way to control a robot, I was wondering if you could give me any information on how you programmed this. I will be competing in a high school robotics competition, and would greatly appreciate any info you could provide on how exactly you programed your arduino, and how you wired the shield to your mouse/arm.
    Thank you very much

  • scc

    Oleg : when i compile arm_mouse.pde i have an error “ServoShield” does not a name type. can u help me?

  • scc

    Mr Oleg: when i compile i have this error: ‘ch9.h:103:error: ‘byte’ does not name a type. and i have the same error for many lines of ch9.h

    • this code has been developed quite some time ago; it’s possible that ‘byte’ is not supported in recent versions of Arduino IDE. Define byte as uint8_t and try again.

  • scc

    Mr Oleg: Can I use Renbotics library without using side Shield? How can i define the pins of Arduino Uno to use this library?

    Regards

  • taipscode

    I don’t know, what’s product board of Mr Oleg ?

  • LordGonk

    This is awesome!
    However, I am having trouble implementing this because of the new USB Host library. What could I do to make this work with the new code? I have not had too much success myself, so any help would be great.

  • ravishankar

    this is an awesome project

    i have a aurdino duemilanove board . i am planning to implement this for my final year electronic project.
    can u pls help
    what are the other hardware required other than serv0 motors and usb mouse?
    and aurdino codes?
    any help would be great

  • rod

    Hi,Oleg!
    Mouse poll error :5
    600
    What about this error?
    What is means 5?

    thank

  • rod

    ok,
    I understood,read you communicating-arduino-with-hid-devices-part-1/
    thank

  • rod

    Hi Oleg!
    One more question
    line 183 in you code

    float grip_angle_r = radians( grip_angle_d )

    Where calculate grip_angle_d?

  • rod

    Hi Oleg!
    One question about inv.kinimatics.Maybe it’ stupid question and you do’t wont to answer.
    My ARM have a two SHL_SERVO , one like in you ARM and second SHL1_SERVO on pin 7 of servo shield. For control i use calculations like this:
    line 205/ float shl_angle_d = degrees( shl_angle_r );
    float shl_angle_d1 = 180.0 – shl_angle_d; //second servo
    because my servo inversely locate in construction of arm
    line 215/ float shl_servopulse = 1500.0 + (( shl_angle_d – 90.0 ) * 6.6 );
    float shl_servopulse1 = 1500.0 + (( shl_angle_d1 – 90.0 ) * 6.6 );
    …………..
    servos.setposition( SHL_SERVO, ftl( shl_servopulse ));
    servos.setposition( ELB_SERVO, ftl( elb_servopulse ));
    servos.setposition( SHL1_SERVO, ftl( shl1_servopulse ));

    and SHL1_SERVO do’t move. For function servos.setposition( SHL1_SERVO, 2100 ) ok, servo move.
    maybe i do’t undestand something or other?

    thank

  • rod

    Hi Oleg!
    What kind of IDE version you for this sketch?
    Is it possible run this sketch in IDE 1.0? or i have
    problem this lib?

    • This code is pretty old. You’ll need legacy library plus pre-1.0 Arduino IDE.

      • rod

        Oleg excuse me one more question/
        in line 137 of this sketch
        case 0x00: //no buttons pressed
        armdata.z_coord += ( buf[ 3 ] * -2 ) ;
        break;

        and for all buttons pressed you use buf[ 3 ], is it correctly? In ‘communicating-arduino-with-hid-devices’ you use another way:
        line 75 -76

        if( buf[ 0 ] & 0x01 ) {
        Serial.print(“Button1 pressed “);

        and line 89 -90

        Serial.print(“Wheel: “);
        Serial.println( buf[ 3 ], DEC);

        separate ‘buf’ for Wheel and Buttons?

  • rod

    OK, thank you. Because i have some problem this targeting of arm. I useing IDE 1.0, this modified old lab, but something not connect.

  • rod

    Oleg excuse me.
    Mouse Poll error:3
    What is means 5?

    thank

  • rod

    i mean 3, sorry

  • rod

    Oleg HI!
    I think, i finde error in my arm.
    One question, I use different datasheet (cd4017be Clock Frequency 11MHz) for servo shield – is it no problem?
    Are you modified servo shield?

  • rod

    Are you modified servo shield lib?

  • rod

    Oleg, sorry but i iteratively ask my question.

    I use different datasheet (cd4017be Clock Frequency 11MHz) for servo shield – is it no problem?
    Are you modified servo shield lib?

  • rod

    Oleg, thank you very much. Sorry for trouble.

    • rod

      Oleg, in Renbotics shield 7 pin of Arduino use for counter reset. In you modif. 5 pin is reset –
      this is write somewere in code, or you do something
      other? Thank for answer.

  • hi. good job i want to list of materials this project. Can you send me?

    • I don’t have it, sorry. You can make this list yourself – main components are listed in the article and the rest is not critical.

  • 1- Lynxmotion AL5D robotic arm
    2- USB Host Shield (HID r.2.0 released)
    3- Aurdion Duemilanove
    4- Mouse
    5- Renbotics Servo Shield

    Do you have these other materials?

  • EDWARD

    Start
    Setup packet error: DError configuring mouse. Return code : D
    HOW to repair it?

  • EDWARD

    Mouse Poll Error: 3
    600
    Mouse Poll Error: 3
    600
    Mouse Poll Error: 3
    600
    Mouse Poll Error: 3
    600
    Mouse Poll Error: 3
    …..the code have a problem……

  • I want to use BotBoarduino, but usb host shield didnt run. Normally Arduino uno r3 run. BotBoarduino may be necerray for set jumper. Have you know a information.?

  • pramod

    hey oleg were can i find the detailed report of this project…..detailed report such as mechanical design,torque for motors and dimensions …i m doing this for my final year project plz send the link if possible

  • charen

    i am a beginner , it would be great help if i get a circuit diagram of this robotic arm . thank you

  • sharon

    Hey oleg,
    Where can i get the header files servoshield.h usb.h