Introduction: Wii Nunchuck As General Purpose Controller Via Arduino Board
I made a self-balancing electric skateboard which is steered using a Wii Nunchuck by either using the thumb joystick on the top or by tilting it left or right, depending on which of the two buttons on the end are being pressed.
A simplified self balancing board is described in the instructable here:
However people are asking me how the Nunchuck steering control used on one of my earlier boards can be used.
The wired Nunchuck can be seen in use as a steering control in the second half of this video:
It can also be seen in use controlling a set of LED's attached to the Arduino ouputs here:
I have another instructable on interfacing a wireless Nunchuck to an Arduino but that is quite tricky and only works with a few specific wireless nunchucks. If starting out I strongly suggest going for the wired standard Nunchuck to begin with as described here.
The purpose of this instructable is to describe how to interface a completely standard Wii Nunchuck (i.e. with a cable) with an Arduino board. The Nunchuck is low cost but powerful with a fully proportional thumb joystick, 2 buttons on the end and a 3 axis accelerometer (position sensor). It is ideal for controlling things with.
The Arduino has been set up to output variable voltages between 0 and 5V which can be used as, for example, steering control inputs for another project such as a robot. You can use the (proper propotional) thumb joystick or the embedded accelerometers (tilt the chuck left right forward or back).
By modifying the code you can easily make it do other things.
I am using an Arduino with a 328 processor (i.e. a recent one) and version 17 of the Arduino software.
The Arduino sketch is attached below.
This is all derived from code developed by Chad Phillips and others, see: http://windmeadow.com/node/42
For more info on wiring up the chuck to the Arduino, download Bionic Arduino Class 4 tutorial which is excellent from TodBot blog:
There is plenty more on this on the net, there is even someone with a Nunchuck controlled electric canoe here:
I am just presenting this all together in one place as a way to get started with something that should work OK.
Step 1: View of Nunchuck Buttons
Here are the "c" and "z" buttons on front of the Nunchuck.
Step 2: Arduino Board Inputs and Outputs
Step 3: Plug on End of Nunchuck Cable
This is the plug on the end of the Nunchuck cable.
On next page I will show a diagram of the connections you see when you look into the end of it.
There are 6 small copper contacts. We will be using the outer 4, the 2 middle ones are not used.
Step 4: Connections Between Nunchuck and Arduino
To connect the Nunchuck to th Arduino I buy a Nunchuck cable extender which has a female socket on one end of it. I cut the socket off with about 6 inches of wire hanging from it, bare the wire end and solder the wires to the arduino board. This way on your project, you just plug your Nunchuck into this female socket which you mount somewhere convenient.
I will explain how to actually do this on next page
Step 5: Connecting Chuck to Arduino
Step 6: Connecting Chuck to Arduino
You are going to cut this cable in half and keep the socket this end as shown by the arrow.
The cut wires will be soldered to the Arduino board.
Step 7: Cutting Extender Cable
You are only going to use 4 of the 6 wires.
Step 8: Pullup Resistors
NOTE: This may change soon. Working on software that will automatically read either a wireless chuck or a wired Nintendo chuck, depending which one you plug into the socket.
Step 9: More About the Outputs
Output Pin 9 is either 0 or 5V, nothing in between. It can be used to cut power to motors for example if neither of the buttons are being pressed on the Nunchuck.
Output Pins 10 and 11 are producing a variable voltage. However this is as a series of pulses of 0 or 5V. To use these as a variable voltage control signal input to another device (as a steering command for example where 2.5V would be "straight ahead") we need to smooth the square wave pulses into a proper stable voltage.
For this we use an RC filter mentioned earlier.
A diagram of how this is set up for each output pin is shown here with values for the resistor and capacitor that I found to work OK.
Step 10: This Module in Use
I used the Nunchuck/Arduino combination as a steering input for a self-balancing skateboard. the variable voltage steering commands were fed into the inputs of an older non-Arduino microcontroller which was doing the "balancing" and controlling power to the two motors.
It worked well and it can be seen in action in the second half of this video: