How to: Arduino and Nintendo Nunchuck for pan and tilt camera interface

Hi all,

this post is an "how to" for an Arduino pan and tilt camera moved by a Nintendo Wii Nunchuck.

Here's the video so you can check how it'll be the result. The most important thing is the precision and responsiveness of the system.

Here it is for all that asked me in the past and for those interested in putting something similar in their UAVs.

It's an "old" project I've posted the following video on YouTube more than a 5 months ago but never had the time to post schematics and the code online, even if a lot of people asked for it.

I use an Arduino Diecimila board to have a Nintendo Wii Nunchuck control a camera mounted on a pan and tilt mechanism with two servos (Hitech HS-422).

Nunchuck's accelerometer (an ADXL330) is used to move the camera.

As you can see, if the Nunchuck's "Z" button is pressed, the camera position is locked.

Here is picture of the pan&tilt mechanics with servos:

First of all I got to thank a few people that before me putted their experiences online. That simple project is based on the code and infos found on the following pages:

Read wii nunchuck data into arduino

Boarduino, Wii Nunchucks, and Servos

Here's a simple schematics on how to connect the servos and Nunchuck to the Arduino. Servo's pins are 6 and 7.

The code is here.

You can find more infos about the code in the two links I mentioned before, but feel free to ask.

The only section you should customize to adapt to your servos an need is a list of variables:

refreshTime (set to 20) - minimum refresh time for servo pulse
minPulse (set to 1000) - minimum pulse value for servo 1
minPulse2 (set to 500) - minimum pulse value for servo 2
dtime (set to10) - delay (in milliseconds) for each loop
pwbuffsize (set to 10) - how many values has to be buffered and the averaged (that's the same value for both servos)

Next post will be regarding the evolution of that interface: changed camera and servos with a smaller and ligher one (this one) and made the connection between the Nunchuck and the camera, wireless.

Hope that can be helpful and feel free to ask anything about that.

Thank you and ciao,


Views: 42018

Comment by Craig on April 16, 2008 at 2:26pm
Also, if anyone has some suggestions for good tutorials some of the electronics/processors, please let me know.
Comment by Andrea Salvatore on April 17, 2008 at 9:35am

you can download a "starting guide" about arduino and arduino programming from here (pdf) and here (pdf).

Those docs are a very good start for Arduino microcontroller.

Otherwise I can suggest you books like "Making Things Talk" and "Physical Computing: Sensing and Controlling the Physical World with Computer" by Tom Igoe.

Online there are a lot of infos... I suggest you to start with that links:

I think that should be enough for now :)

Let me know if I can help you somehow.

Comment by dborup on April 18, 2008 at 8:07am
9: error: #include expects "FILENAME" or In function 'void setup()':
In function 'void nunchuck_init()':
In function 'void send_zero()':
In function 'void loop()':
In function 'void printNunchuckData()':
In function 'void muovi()':

i get all these errors when i try to compile the code?
Comment by Andrea Salvatore on April 18, 2008 at 8:50am
I'm sorry. I got problems in cutting and pasting the code. Some parts of the code is cutted by the blogging platform.
I'll put on my website to be dowloaded.
Comment by Craig on April 18, 2008 at 4:42pm
Thanks Andrea!
Comment by iceman246 on June 20, 2008 at 5:06am
hi I am trying to duplicate what you are doing it is very cool. I am new to this and I can't figure out how to get the code to upload to the arduino. It keeps giving me messages like this
"/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected unqualified-id before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected unqualified-id before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:267: error: expected `)' before 'int'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__put' was not declared in this scope

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'char'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: '__get' was not declared in this scope

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: expected primary-expression before 'struct'

/Applications/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:420: error: initializer expression list treated as compound expression

Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex': No such file

avrdude: can't open input file /Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex: No such file or directory
avrdude: write to file '/Users/IanCivgin/Documents/Arduino/sketch_080619a/applet/sketch_080619a.hex' failed"

Help would be greatly appreciated. If there is an error in your code or if you know how to fix it just let me know.

Comment by Michael H on August 5, 2008 at 6:40pm
Can someone answer the above post please? I am having the same problem with vista.

I get the error message:
Couldn't determine program size: C:\Users\albert\Desktop\arduino-0011\hardware/tools/avr/bin/avr-size: 'C:\Users\alber\AppData\Local\Temp\build3482.tmp\wiinunchuck.hex': No such file

Comment by Amoisonic on February 13, 2009 at 10:33am
Can't we modify the code? Instead of using pinout 6 & 7 output 2 single servo pulse for controlling 2 servos,we use pinout 6 or 7 ONLY to send out a series of 8 channel pulse train(channel 7 & 8 for camera pan & tilt controls).then we can hook it up to Futaba remote with trainer connection .We can build our own head tracking camera control for FPV piloting.
Comment by Reto on February 27, 2009 at 4:11am
I just got my brand new chinese Nunchuck today and I am eager to try this out. Before I start, I have a basic question: why connect the Nunchuck to 5V since it is a 3.3V device? Isn't the higher Vcc going to shorten the life span of the Nunchuck? Could I use the 3.3V port of my Duemilanove Arduino board instead for powering the Nunchuck or is there code to modify for this to run? Thanks for helping a newbie!
Comment by Reto on February 27, 2009 at 6:46am
A I said before, I am eager to play with my Nunchuck and Arduino. I'll use the +3.3V connector of the Arduino to power the device. Since, as I read, the Nunchuck uses the "fast" i2C protocol, the TWI frequency of wire.h arduino library has to be changed to 400kHz for a +5V powered Nunchuck. If the device is powered with the +3.3V supply, the frequency should be set to 100kHz. So I'll change the wire.h TWI_FREQ line to "#define TWI_FREQ 100000L". I think the +3.3V is better suited for the Nunchuck. I read somewhere (forgot to bookmark) the Vcc should be below 4V!
I'll report back once if it works. In the meantime, if this setting seems strange to someone, please let me know. I also hope the current draw of the Nunchuck is not more than the arduino +3.3V port can deliver.


You need to be a member of DIY Drones to add comments!

Join DIY Drones


Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service