Introduction: Arduino Powered Bionic Arm
Hi, my name is Frans and in this instructable I will teach you how to create a bionic arm from scratch! Our goal is to create a stable and reliable arm mainframe that is able to move much like a real human arm would! Before we start I will list all the required materials. Please feel free to experiment with different materials or code!
Please note that I will not go into making the wooden mount for the arm. I chose not to include that in the steps because my wood working skills are terrible and the point of the arm is that it is modular, which means you could basically hang it anywhere and it will work! Feel free to design a proper mount that is not held together by tyraps.
List of required materials:
- 1x Arduino Uno + Power cable.
- Arduino breadboard + long jumper wires.
- 3x Servo.
- 3x Servo wings + corresponding screws.
- Sheet of aluminium (approx. 40x20 cm should be sufficient).
- General tools (a set of screwdrivers, screws, hammer, workbench).
- A laptop or computer that can run Arduino software.
- Wii Nunchuck + Nunchuck shield.
- Tools to cut light metals.
Difficulty: average - requires solid knowledge of basic Arduino functions and tools. I strive to explain everything in detail so that Arduino newbies like myself can follow this guide without any major issues.
Step 1: Creating the Aluminum Cutouts
The first thing we're going to do is to create the frame in which our servo's will be placed.
First, grab the aluminum sheet and cut out the lower arm and upper arm strip. There is no real right or wrong when it comes to the sizes of these parts as you match your other frame parts with the size you choose here. Personally I went with a lower arm of 15 cm in length with a width of 2 cm and an upper arm of 13 cm in length and with a width of 4 cm. Adjust sizes as you see fit.
Important thing to note on picking a size: Make sure to adjust your arm's width to the width of your servo, as a rule of thumb you should make it at least 1.5 / 2 cm longer in width than your servo's width so you have plenty of room for the hole the servo is placed in.
Now we also want to make two cutouts for our rotation mechanism. Cut out another two stripes that are roughly of the same width as your upper arm.
Step 2: Processing the Aluminum Cutouts
So you got your aluminum cutouts all sorted out? Great! The next step is to actually process the aluminum in a way so that we can insert our servos into them. The way you want to cut these things is actually by using a punch machine, also known as a 'pons' machine in dutch. The first picture in this step shows the machine and the way it works.
First of all, there are four holes we have to create for the standard arm that uses 3 servos to move. If you followed the previous step correctly you should now have:
- 2x aluminum strip for upper arm and lower arm
- 2x aluminum strip for the rotation mechanism.
In order to get the cutouts right you want to measure up the size of the servos you're going to use. We'll start with the upper arm. This strip gets one cut, which is for the upper arm servo. Match the size of the cutout according to the servo size that you will place in it.
Up next is the rotating mechanism. Cut both of them according to the picture. One will get 1 cut and the other one will get two cuts. All set? Let's move on.
Step 3: Attaching the Servos and Assembly
Congratulations on coming this far! Now we have all our tools, all we have to do is to properly attach them. It is very important to tightly fasten components to the frame properly. Failing to do so could result in trembling motions and or other defects and instabilities.
It is easiest to start with the rotation parts and work your way down to the arm parts.
Important note: before you start mounting your servos, make sure your servo wing is properly secured to the servo by using the corresponding screw. There will be no way to access the top of the blade once it's mounted!
Important note #2: Before adding the servos to the frame, make sure to turn them entirely one way either with your hand or by running a script. This will make setting up your code lots easier later on in the process!
Firstly, mount your servo in the cutout you made in the upper rotation part. If you cut it correctly, it should slide in perfectly. Now take it out and drill holes for the attachment hinge on the servo (circled red in the attached image), there should be a hinge on either side of the servo. All done? Screw it fast!
Now you want to attach the wing of the servo to the lower part of the rotation part as is shown in the picture. The easiest way to do so is to measure the wing's length and mark the place where the drill holes have to go. Then simply proceed to drill the marked holes and screw the wing fast! Voila!
For the other two servos there is not much more to it, just rinse and repeat. Make sure to use the attached picture as reference. There is no way to go wrong here. As you can see in the picture, I chose to pick a bigger upper arm servo, this is not necessary but it is definitely worth considering as it will give your arm much more power and stability than a micro servo would.
Step 4: Connecting the Arm to Arduino!
Now that we have everything all set up it is time to connect our arm to Arduino and start testing. It is fairly easy to hook servos up to Arduino but I will make a small scheme just to be sure.
Note: I added a capacitor to the energy flow of my larger servo so that it divides the current flow more evenly. It is not a necessity but if your servo starts misbehaving or twitching it would be wise to add one before looking at other possible causes.
Servos are fairly easy to connect, start by taking a look at the cables that come out of it. In almost all cases there should be three wires colored yellow -> red -> brown or brown -> red -> yellow respectively. To connect your servos, make use of the scheme below:
- Yellow wire -This is the cable that you want to connect to either a digital or analog port on your Arduino depending on whether you have an analog servo or a digital servo.
- Red wire - This is the power supplement for the Servo, should always be connected to the 5V output on Arduino.
- Brown wire - This is the ground cable for your servo. Make sure to plug this into the ground (or GND) plug on Arduino.
Because we're using three servos there will not be enough space for all cables to be directly plugged into the Arduino board. Luckily, there is an easy and effective solution: breadboards! A breadboard needs just one wire from an Arduino port to a row on the breadboard to multiply that port as many times as you like. Because we'll have three ground cables and three 5V cables we'll definitely need to use a breadboard.
Note: In this tutorial I will be using a solder-less breadboard so that I can easily adjust wires and make changes to my prototype, this does not mean that soldering breadboards won't work!
Step 5: Adding the Code
We're almost done! We are now going to add the code. To do so, you will need to have the Arduino IDE installed on your computer or laptop. Now connect your Arduino to it and launch the program called 'Arduino'.
Unlike what most people think it is fairly easy to program anything into the Arduino, especially when you can snatch the full code from this crazy helpful instructable! I have added a download link below. Here's how to use it:
- Download the full .zip file containing all the code.
- Extract the .zip file anywhere you like.
- Open it up using your Arduino program (if not set by default) and (once your Arduino is connected) hit the upload button. This will send the code to your Arduino. Once uploaded, your servos should move to the default resting position of the arm. This is a good sign!
I will try to update this code troubleshooting section as much as possible, feel free to ask me anything in the comments!
Q1: I got a compiler error while building, what should I check first?
A1: The most important thing to this code is connecting your servos to the right digital ports. In the code these servos are set to:
- Port 11 for the Upper arm servo
- Port 10 for the Lower arm servo
- Port 12 for the Turner servo
Feel free to assign these servos to other points but don't forget to adjust the code. The syntax goes as follows: ServoName.attach(digital pin you put the servo into).
Note: To keep this as simple as possible I will not do a breakdown of the code in this step but you needn't fear. For everyone wondering what is going on inside the code I would like you to refer to the last step, which is an optional step where I break down the code piece by piece, explaining how the code functions and controls your arm along the way!
Credits: The code used in this tutorial was built upon a base library for Wii Nunchucks made by Tod E. Kurt, you can find him and his awesome creations at https://todbot.com.
Step 6: Connecting the Nunchuck
We've finally come down to the last necessary step to get our Bionic Arm working. If you've gotten this far, connecting your Nunchuck should be a breeze!
All you have to do to connect it is insert your Wii Nunchuck shield for Arduino into your Wii Nunchuck. To do it correctly you should make sure that the text on your Wii shield matches with the Nintendo text on the Nunchuck so that those two sides are facing up when connected to Arduino (as shown in the picture). Done? Good! Now put the arduino into the first four Analog pins on your Arduino (also shown in the picture).
Because we've already added the code this should work instantly, there is no need to hassle with code because the code you downloaded in the previous step also includes the necessary byte libraries to send and receive input to and from Arduino. Your arm is now functional, please refer to the next step for controls!
Step 7: All Default Arm Controls
Controlling the bionic arm is easy!
First of all, in order for the arm to follow your movements you musthold the c button. It will only react to thumbstick controls when you don't hold this button. I programmed the arm that way to make the arm hold its position better when you don't want it to move.
Once you are holding the c button you can aim the nunchuck up and down, the arm will mimic that movement. You control the turning servo of the arm by tilting the nunchuck either to the left or the right side. A common mistake most first time users make is actually moving the servo in swiping gestures. These movements will not be registered because there is no accelerometer present in the nunchuck, just a gyroscope. Don't worry though, it handles the job perfectly.
Finally there is the thumbstick on top of the Nunchuck only functions along its vertical axis, meaning that you control the lower arm of the bionic arm by pushing the thumbstick up and down. Once you let go of the thumbstick it will revert back to its default position at a 90 degree angle.
Have a look at the pictures and video for a good look at how my prototype arm worked out! Enjoy your self-made bionic arm!
Step 8: (Additional) - Code Breakdown
Made your arm and wonder how to adjust to code to your liking? Look no further because in this section I will point out the most important bits of code I gave you so that you can freely experiment with all its functions. Go ahead and open up the code and keep on reading!
1) As you can read from the comments in this part, this code handles all initialization functions. We start off by including basic libraries and and also the Wii Nunchuck library . We then create names for our axis and for our servos so that we can assign things to these names later.
2) This is where we start when you power on the Arduino. We start by setting the Serialmode to (19200), which is the correct mode for using a Nunchuck with Arduino. Then we attach all three servos based on the digital ports we connected them to. After that we make sure that we 'Write' all the servos to their default position when starting it up. When everything is set up we print that the arm is ready to follow your commands
3) The loop is the function that is continuously, hence why we put our actual movement scripts in here. We start out by taking the variables like 'accx' and 'accy' from the nunchuck library we included in step 1 and we form them to variables that we can work with. We also add the variable joyx and joyx, these are the joystick x and y axis controllers.
The numbers the servos are going to be writing when using the arm are going to be manipulated versions of the basic 'accx' and 'accy' values that we got from our nunchuck library. We manipulate the values these variables give us because they do not range from 0 to 180 but usually from 70-190. Most servos can only handle a 180 degree turn and that is why we map the values to not range from 70 to 190 but to 0 to 180.
Still don't understand what's going on? Here's an example: When I map a value range that would normally give results between 70-190 to 0 - 180 this means that where the lowest value would normally be 70 it would now be 0. This goes both ways because the new 190 now only goes up until 180. Mapping is extremely useful for controlling devices that only accept limited value inputs.
4) The actual movement part of the loop
We move the servo by making it 'write' (which means moving it to a desired angle between 0 and 180) the mapped values from step 3. Before we do so, we check if our mapped values are indeed between 0 and 180 because any other value could cause malfunction or even a servo defect when the servo is continuously asked to push against its own boundaries.
The first thing we do is check if the thumbstick value has changed, which is set based upon the angle in which the thumbstick on top of the Nunchuck is held. Then we follow up with an 'if' statement, checking if the 'c' button is held down. Like I said in the controls section of this instructables; the arm will only function when this button is held down. Feel free to remove this statement and see if you like that better, but for a stable arm I would highly suggest leaving this condition in place.
C button pressed? Good! This means that the servos will now also write all data from our mapped y-axis and x-axis values that are set by in which angle and pitch our Arduino is held. That's all there is to it.
So there you have it, my full explanation of the code! If you would like to learn more about the actual byte-reading part of the code that is done in the library I used from TodBot I would kindly refer you to his blog! I in no way take credit for the attached library I refer to in my codes.
Note: For those of you wondering why there is a delay between each movement and also between each loop check; this is to prevent the input of the nunchuck to flood the servos with commands. Removing the delay will cause a byte overload on the receiver side of the nunchuck, which in turn will cause inaccurate movement of your arm or even malfunction.