Skip to content

Wii Nunchuck Mouse

In this short article Frank provides example code to use the Nintendo Wii Nunchuck as a mouse. In this previous article we looked at the Nunchuck and an adaptor board I purchased from Todbot. I also mentioned making a mouse device using the Nunchuck using ideas from Bernard’s Accelerometer Based Mouse article. Frank has done the hard work to make this easy for us.

This article was submitted by Frank Zhao as part of the “Hobby parts for articles” program.

Hardware and software so that you can use a Wii Nunchuck controller as a computer mouse.

This example software uses the joystick for mouse movements. Z button for left click, C button for right click.

Tilt via the Nunchuck accelerometers are used for mouse wheel scrolling, middle clicks, and also the "back" button in Internet browsers.

An Arduino microcontroller provides the hardware interface, reading data from the Nunchuck and sending the measurements to the PC via a serial port. The source code package includes a project file for use with the Arduino IDE.

Autoit is used on the PC side to convert the serial data from the AVR microcontroller into mouse movements and key presses. Autoit is a freeware BASIC-like scripting language designed to simulate keystrokes and mouse movements in Windows. The Autoit source code and executable are included in the package below.

AVR ATMega168 Microcontroller source package

Autoit source code and executable package

Update: Frank looked over his code and made improvements. The zip files linked above has been updated with his new files. The new code works with the Arduino. If you have already picked up the files, ditch what you have and get the new stuff.

Update2: Frank provided a great code breakdown for the code used in this article. It’s posted as a new article here.

Links to related information.

Posted in Development Tools, Electronics Links, Microcontroller, Projects.

2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. JPC says


    Thanks for great article. I’ve made some improvements on the autoit code to emulate the doubling of mickey / pixels ratio when mouse speed go over a certain value (needed for large movements). In my case, value readed is divided by two (no change from original code) when absolute value is under 40 and mulitiplied by two when > 40 (the modification). This allows faster displacements when joystck is at its max.


    Original code
    $temp = _CommReadByte(1)
    $moveX = ($temp – 63) / 2

    $temp = _CommReadByte(1)
    $moveY = ($temp – 63) / 2

    $mouse = MouseGetPos()

    Is replaced with :
    $temp = _CommReadByte(1)
    $moveX = ($temp – 63)

    if ( ($moveX > 0) and ($moveX -40)) Then
    $moveX = $moveX / 2
    $moveX = $moveX * 2
    $temp = _CommReadByte(1)
    $moveY = ($temp – 63)

    if ( ($moveY > 0) and ($moveY -40)) Then
    $moveY = $moveY / 2
    $moveY = $moveY * 2

    $mouse = MouseGetPos()

  2. dfowler says

    Frank provided a detailed code breakdown at the link below