Introduction: Simple 3 Button Controller for a 4 Axis Robot Arm
In this Instructable, I will show you how I set up a 3 button controller for a 4 axis robot arm.
A quick breakdown of what everything does
Button S1 lets you choose which servo motor you want to move.
Buttons S2 and S3 control the direction of movement of the selected servo motor.
The 4 LEDs show you which servo motor is currently active.
Why did I use an Arduino Nano, and not a normal Arduino Uno?
I decided to use an Arduino Nano in this project because:
They are cheap and have just enough room for everything I needed.
I plan to solder the Nano into a printed circuit board version of this circuit later on.
However, if you don't have a Nano, an Arduino Uno will do just fine.
There's a lot of cables involved in this project, but don't get put off from trying it, it's actually pretty simple.
Step 1: What You Need to Build the Circuit
An Arduino Nano ( an Uno or Mega will also work just fine)
A 4 x AA battery pack (Please note: a single 9v battery will not work!)
https://www.adafruit.com/products/830 (I like this one because it has an on/off switch) $2.95
3 x momentary push buttons
https://www.adafruit.com/products/1119 (ten pack) $2.50
4 x coloured LEDs (any colours are fine)
https://www.sparkfun.com/products/12062 (20 pack various colours) $2.95
3 x 10k Ohm resistors (Brown Black Orange)
4 x 330 Ohm resistors (Orange Orange Brown)
https://www.sparkfun.com/products/10969 (great pack with loads of different values) $7.95
1 x 40 pack of male/male jumper wires
4 x Servo motors
As I was planning to actually have these motors do a bit of work I upgraded from my normal cheapies to this model:
https://www.adafruit.com/products/1143 (they are $9.95 each) $39.80
Total cost of the project: @ $70
Step 2: Installing the Arduino Nano and Arranging the Power on the Breadboard
Insert the Arduino Nano into the breadboard as shown in the diagram.
Note: The legs are quite stiff so you might want to bend them just a little bit on a flat surface if you have problems getting the legs to line up with the holes on the breadboard.
Arranging Power to the breadboard
I plan to power the servo motors from the 4 x AA battery pack which I will plug into the bottom power rails of the breadboard.
The push buttons and LEDs will be powered by the Arduino's 5v line which I will connect to the breadboard's top power rails.
Ground will be shared between the Arduino and the battery pack.
Note 1: The Arduino doesn't output enough power to run all 4 servos and you risk damaging it if you try running all of them from the Arduino's 5v line.
Note 2: I have tied the Arduino ground into the battery ground to help stabilize the circuit, this is an important step, don't miss it out.
Step 3: Installing the Push Buttons
First let's remove the battery from the circuit so we don't zap anything by mistake as we go along.
(We can put it back once we have everything hooked up and have checked for mistakes.)
One side of the push button has a 10k resistor tied into the positive power rail (connected to the Arduino 5v line).
For some background information on how pull-up resistors work please read this page: https://learn.sparkfun.com/tutorials/pull-up-resis...
The other side of the switch connects to ground. Next we take a jumper cable, plug it into the same line as the resistor, and connect the other end into an Arduino digital port (see the diagram.)
S1 is the button we will use to select a servo and is connected to D2 on the Arduino.
S2 will move the servo left and is connected to D3 on the Arduino.
S3 will move the servo right and is connected to D4 on the Arduino.
Step 4: Installing the LEDs and Their Resistors
A few notes on LEDs:
When you look at an LED you will see that the 2 legs are different lengths. The long leg is the positive side of the LED, and the short leg is ground on the LED. Also if you look carefully at the head of the LED you will see that there are two pieces of metal, one small and one big, the small one is the positive side of the LED
Connecting the LEDs to the circuit
Push the two legs of the LED into the breadboard and connect the short leg to ground.
Place a 330 Ohm resistor into the same line as the positive leg as shown in the diagram. A jumper cable then connects from the same line as the resistor to a digital port on the Arduino (see the diagram.)
The jumper cable from LED 1 connects to D9 on the Arduino.
The jumper cable from LED 2 connects to D10 on the Arduino.
The jumper cable from LED 3 connects to D11 on the Arduino.
The jumper cable from LED 4 connects to D12 on the Arduino.
Note: If an LED gets too much power running through it can break, so the resistor is used to protect it, limiting how much power gets through to the LED.
The function of the LEDs is to show which servo motor is currently selected.
Step 5: Installing the Servo Motors
A few notes on Servo Motors:
Servo motors have 3 cables connected to them. A positive, a negative and a signal. The colour code for servos is tricky because there are several possible color combinations depending on the servo and who made them. I include a diagram showing the most common combinations.
Connecting the Servos to the circuit:
Using male/male jumper cables connect the ground (negative) of the servo to the bottom ground rail on the breadboard (coloured blue in my diagram.) Connect the positive line of the servo to the positive power rail at the bottom of the breadboard (coloured red on my diagram.) The signal cable from the servo connects to a digital port on the Arduino.
Once you have connected up the servos as shown in the diagram, take a few minutes to check all your connections and then insert the battery cables into the breadboard's bottom power rails.
Servo 1 signal cable connects to D5
Servo 2 signal cable connects to D6
Servo 3 signal cable connects to D7
Servo 4 signal cable connects to D8
Once that is all done, we have finished the physical set up and are ready to get on with the programming.
Step 6: The Program Part 1
So how does the program work?
The first thing the program does is set all 4 servos to the middle of their arc of movement. If you are building a robot arm, you may want to run the program once before you build the actual robot so you can set it up in its default position.
When you press S1, the Arduino detects this button press, and lights up the first LED, it then activates the movement buttons S2 and S3, and also activates servo motor 1.
When you press one of movement buttons (S2 and S3) the Arduino sends a signal to the servo motor to move 1 degree in the correct direction (left for S2 and right for S3.)
It will do this every time you press the movement button until the servo's maximum or minimum movement angle is reached.
Pressing S1 again makes the next LED light up and servo 2 becomes active, you can then move that servo motor's position. Keep pressing S1 to cycle through the servos until you get to the one you want to move.
Step 7: The Program: 2 (updated Code for This As the Previous Version Was Incomplete)
Here is the program needed to run the circuit, download it, have a look through the notes and post up any questions you have if the function of anything isn't clear.I hope you have found this Instructable useful, and don't forget to BUILD IT :)
(You probably should buy some female/female jumper cables, I found that when I actually build the robot that I needed to extend the cables out quite a bit.)
We have a be nice policy.
Please be positive and constructive.