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: 28859

Tags: accelerometer, adxl330, arduino, camera, nunchuck, pan, servo, tilt

Comment by Andrea Salvatore on February 27, 2009 at 6:59am

you are right. You can use the 3.3V that the Arduino board has. It's between the RESET and the regulat 5V output. I hope this helps.

Comment by Reto on February 27, 2009 at 3:51pm
Hey Andrea, your Nunchuck hack works like a dream!!! I had to search some wiki to find out how the connector wiring was pinned because my chinese Nunchuck has not the same wire colors as yours. In case some other people get an Ebay Nunchuck from China, that's how it is wired:
VCC = Brown (I connected at +3.3V)
GND = White
Data = Green
Clock = Blue
I have one more Black wire to the connector shield.
Well, this was to tell that it works very nicely after setting up minPulse variables to get the Nunchuck centered as I wanted it.
I would like to avoid the very tiny servos movements when the Nunchuck is staying almost without moving. Would you have some suggestion for code modification to try maybe to average 3 consecutive pulsewidths, or eventually to discard servo movement if absolute value of new pulsewidth minus old pulsewidth is lower than some threshold?
I am very new at Arduino and coding is not easy for me. If you or anybody have some suggestion about the best way to make the servos stay still when there is almost no movement on the Nunchuck, that would very useful and I would be very grateful.
Comment by Jonathan Robson on March 15, 2009 at 4:41am

This is a perfect starting point for a project I'm working on but I'm is shanghai and your ideavirus server is blocked in China so I can't see the code. Would you mind posting it on diydrones ? many thanks.
Comment by Reto on March 15, 2009 at 8:53am
Here's the code: arduino_nunchuck.pde
Comment by Jonathan Robson on March 16, 2009 at 3:52am
Thanks. Strange - I bought my nunchuck from the fake wii shop round the corner here in Shanghai and got a US wire coloured one.
Comment by Reto on March 16, 2009 at 6:13am
The Ebay copy from China had different cable colors, but more importantly, I was a very different, single sided, PCB board. The original is double sided with the accelerometer on one side and the uC on the other. The copy has both on one side. this would not be a problem, but the quality of the board printing was very bad and eventual soldering is taking of the print very rapidly, making the board almost unusable. My modification experience with the original was very good compared to the copy. But if you do not have to modify the board or solder connections, then the copy works just as well.
Comment by Byron Morgan on May 19, 2009 at 6:54pm
I am working with a 2009, and getting errors on compile/load. I hope I'm just doing something wrong....suggestions?
C:\Users\Byron\AppData\Local\Temp\build64951.tmp\core.a(wiring_serial.c.o): In function `__vector_18':
C:\Users\Byron\Desktop\Arduino\arduino-0015\hardware\cores\arduino/wiring_serial.c:112: multiple definition of `__vector_18'
C:\Users\Byron\AppData\Local\Temp\build64951.tmp\core.a(HardwareSerial.cpp.o):C:\Users\Byron\Desktop\Arduino\arduino-0015\hardware\cores\arduino/HardwareSerial.cpp:95: first defined here
Couldn't determine program size: C:\Users\Byron\Desktop\Arduino\arduino-0015\hardware/tools/avr/bin/avr-size: 'C:\Users\Byron\AppData\Local\Temp\build64951.tmp\WiiBot.hex': No such file
Comment by Mike on July 18, 2009 at 9:37pm
When I try to upload the code to the arduino, I get error:
avrdude: can't open input file C:\Documents and Settings\Mike\My Documents\Arduino\arduino_nunchuck\applet\arduino_nunchuck.hex: No such file or directory
avrdude: write to file 'C:\Documents and Settings\Mike\My Documents\Arduino\arduino_nunchuck\applet\arduino_nunchuck.hex' failed

Please help. Mike
Comment by Robuschi Luca on October 2, 2009 at 3:27pm
Ciao Andrea
Correggi la riga 37 con serial.begin e non beginserial come hai scritto altrimenti quelli ignoranti come me diventano scemi nel capire perchè non funziona...
Grazie per aver condiviso il progetto!
Comment by Kevin Bezjak on June 7, 2010 at 8:51am
Hey this project seems really sweet. I think I might try it out myself. Do you have any ideas on maing it wireless? I've heard a lot about these xbee wireless things but I don't know too much about their capabilities.


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

Join DIY Drones

© 2014   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service