I²C for Arduino joystick control

November 2, 2017 Jeremy Cook, Engineering Consultant

As discussed previously, I²C provides an excellent and freely usable standard for short range interfaces between integrated circuits. This can make a great platform for human-machine interface (HMI) setups. Instead of buttons, potentiometers, and the like being fed directly into your microprocessor—increasing wiring complexity and processor overhead—you can take care of this with a few wires, and the near-ubiquitous I²C protocol.

One such interface device is the Wii Nunchuck, clones of which are available online for under $5. For wired robotics control, or perhaps even an animated costume as seen here, it’s hard to beat these little devices. In order to see just how easily (or hard) it is to implement this protocol, I followed along with these instructions on Arduino’s site. While I found it fairly easy to get things communicating, there were a few small things that I had to watch out for along the way.

Library installation

Installing libraries in the Arduino IDE is generally extremely easy, as most can be searched and installed with the click of a button. In this case, however, I had to download the directory found here as a .ZIP file, unpacked it, then placed the Wii-Nunchuck folder into my Arduino/libraries folder. After a restart, this library showed up without issue. While not extremely challenging, it may cause some confusion for those used to installing libraries the other way. Another potential source of confusion is that, as of this writing, if you try to search for “nunchuck” under the library manager, you’ll find a different one than used here.


If you’re going to purchase a Wii Nunchuck for microcontroller use, adapters that will break out its connector without damage can be had for around $1.00. While a good option, if you need to interface your controller without waiting for an extra board, or if you don’t care about reusing your Nunchuck, you can also just cut the plug off and connect the wires as I did. You’ll want to keep the plug around, however, in order to tell which wire goes where.

Looking at the connector, there are six pins, the middle two of which are not used. The upper left is the data (SDA) line, which goes to Arduino pin A4, the lower left is the ground, the upper right is 3.3VDC, and the lower right goes to A5 as the clock (SCL) line. I soldered jumper pins to each of the wires I was going to use, then plugged them in as required.


With it hooked up, I then input the program found on the Arduino project page. However, I had to change one line to read <nunchuk.h> instead of “nunchuk.h” as written. While I wasn’t able to get the processing sketch to work correctly, I turned on the serial monitor under “tools” to see if my Arduino board was interacting with the Nunchuck and was pleased to see that values were indeed changing depending on which direction I moved the joystick. Button presses were also registering properly as 1s and 0s.

Feedback on a screen is great, but in order to show that I could control the Arduino itself with it, I modified the code found there to include lighting up the built in LED on my Arduino Uno Clone depending on if on if the “Z” button was pushed. This gave me the feedback I was expecting, and from there this kind of control could be extended to many other uses, from robotics control to alternate computer interface devices. It’s a great tool to have at your disposal, and working with this controller could be a nice, hands-on intro to using I²C.

Jeremy S. Cook is a freelance tech journalist and engineering consultant with over 10 years of factory automation experience. An avid maker and experimenter, you can see some of his exploits on the Jeremy Cook’s Projects YouTube Channel.

Previous Article
Control your Christmas lights with an Arduino relay board and a mobile phone
Control your Christmas lights with an Arduino relay board and a mobile phone

The Christmas Light Controller is a fun project that lets you provide public access to your outdoor lights ...

Next Video
Adacore discusses "Make with Ada" challenge and new product announcement at #ARM TechCon 2017
Adacore discusses "Make with Ada" challenge and new product announcement at #ARM TechCon 2017

Jamie Ayre with Adacore talks to Rich Nass with Embedded Computing Design about the ``Make with Ada'' chall...