Joystick Controlled Robot Arm Using An Arduino
Joystick Controlled Robot Arm Using An Arduino
This instructable is a hand-in for a school project that we made. The purpose of this
project was to create a robot arm control using thumbsticks. We had to use an Arduino
Uno for the control and in addition, we had to implement some sort of actuator or sensor
in the setup. We modified a Logitech gamepad using the two thumbsticks. Two push
buttons where available to use, but only one activates the magnet (on L3), and the button
on R3 is unused. Our school had a robot arm, a Logitech gamepad controller, an
electromagnet and two thumbsticks made available to us.
[http://www.ebay.com/itm/NEW-UNO-R3-ATmega328P-CH340-Mini-USB-Board-for-
Compatible-Arduino-/311155383820?hash=item48724e5e0c:g:QKMAAOSwdpxUU0UP]
- Bredboard
[http://www.ebay.com/itm/1PCS-Mini-Prototype-Solderless-Breadboard-400-Contacts-For-
arduino-Raspberry-pi-/151909047511?hash=item235e7c1cd7:g:6AMAAOSw7FRWZlbJ]
[http://www.ebay.com/itm/2x-3D-Controller-Joystick-Sensor-Module-Replacement-
ThumbStick-for-Xbox-One-/301845670210?hash=item4647676942:g:35sAAOSwT~9WlFx7]
- 5v Electromagnet
[http://www.ebay.com/itm/DC-5V-0-8A-Electric-Lifting-Magnet-11LB-5Kg-Holding-
Electromagnet-Lift-Solenoid-/201262661479?
hash=item2edc307f67:g:MhUAAOSwT6pVg4Sv]
- 5v DC Power Supply
[http://www.ebay.com/itm/New-DC5V-3-8A-20W-Universal-Regulated-Switching-Power-
Supply-Adapter-AC-100-265V-/121524932692?
hash=item1c4b735054:g:i1AAAOSwyZ5UmDXQ]
[http://www.ebay.com/itm/DIY-4-Axis-Servos-Control-Palletizing-Robot-Arm-Model-for-
Arduino-UNO-MEGA2560-/351150915118?hash=item51c239be2e:g:5TgAAOSwVFlT9D5H]
[http://www.ebay.com/itm/Logitech-Precision-Pc-Controller-Game-pad-/172201040957?
hash=item2817fb5c3d:g:TMEAAOSwYmZXMd9n]
[http://www.ebay.com/itm/10K-Ohm-0-25w-Carbon-Resistors-1-4w-Resistor-10-20-or-50-Per-
Pack-UK-Seller-/172097237753?
var=&hash=item2811cb72f9:m:mU93P7fRSLcp2Eltt2Ud3Rg]
[http://www.ebay.com/itm/65pcs-Solderless-Flexible-Breadboard-Jump-Cable-Wires-Male-
to-Male-for-Arduino-/281544756865?hash=item418d600e81:g:NRUAAOSw7ThUkDmO]
This is what the gamepad looked like before modification. Since we decided that
thumbsticks where the way to go, we had to cut away and replace the gut of the gamepad
[First picture].
We modified the gamepad, so it had to thumbsticks instead of a d-pad and command
buttons. We soldered the thumbsticks on a PCB board and wired them. Two 10K Ohm
resistors where also soldered to the push buttons of the thumbsticks [2nd - 5th picture].
We made two large holes on the front panel, so the two thumbsticks would fit in [Last
picture].
#include <Servo.h>
// Create servo objects
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int angle1;
int angle2;
int angle3;
int angle4;
int value1;
int value2;
int value3;
int value4;
void setup()
servo1.attach(5);
servo2.attach(6);
servo3.attach(9);
servo4.attach(10);
void loop()
{
value1 = analogRead(pin0);
value2 = analogRead(pin1);
value3 = analogRead(pin2);
value4 = analogRead(pin3);
// 10 bit value is too big, so we change the scale from 0 - 1023 proportionately to 1 - 29
// it needs correction of positions, because joysticks are not very precise to stay exactly in the center
if(value1 <= 17 && value1 >= 13) // if value1 if between 13-17, then it's equal to 15 */
value1 = 15;
value2 = 15;
value3 = 15;
value4 = 15;
// Change initial value 'forservo' which is used to turn servo slower. This value has got very big scale.
// We add or substract (depends on turning direction) difference between analog value and center from
'forservo'
forservo1 = 1;
if(forservo1 > 20000) // if forservo1 is greater than 20000, then it's equal to 20000
forservo1 = 20000;
if(forservo2 < 1)
forservo2 = 1;
forservo2 = 20000;
if(forservo3 < 1)
forservo3 = 1;
forservo3 = 20000;
if(forservo4 < 1)
forservo4 = 1;
forservo4 = 20000;
// change used value to angle of servo. Angles are adjusted during testing
servo1.write(angle1);
servo2.write(angle2);
servo3.write(angle3);
servo4.write(angle4);