Arduino Wii Nunchuck Controller

17,130

303

15

Introduction: Arduino Wii Nunchuck Controller

How to control 2 servos thought the wii nunchuck.

Step 1: Parts

Wii nunchuck

Arduino

2 Servo

Breadboard

Jumper Wires

Step 2: Connect

Connect the wii nunchuck like this schematic.

Step 3: Upload the Code


Step 4: Done!!!

You can now control the 2 servos throught the wii nunchuck.Hope you enjoy!!

1 Person Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

15 Discussions

0
NoahTube HD
NoahTube HD

Question 2 years ago

can I do it with one servo?

0
Alexan24
Alexan24

Answer 2 years ago

Of course, you can. Just don't add one servo. Or, if you want to change the code, you can tell me here or on a pm and I will help you!

0
RoccoV3
RoccoV3

4 years ago

ciao ho provato il codice... avrei una domanda come faccio funzionare i due servo con il joy senza muovere il telecomando ?

0
Alexan24
Alexan24

Reply 4 years ago

Non riesco a capire quello che voglio dire.Prova a scrivere in inglese.

0
aaron2016
aaron2016

5 years ago

I can't download the code, can u just write it on step #3

0
Alexan24
Alexan24

Reply 5 years ago

Here you are!!


#include <Servo.h>
Servo servo1;
Servo servo2;
#include <Wire.h>


#define ZEROX 530
#define ZEROY 530
#define ZEROZ 530


#define WII_NUNCHUK_I2C_ADDRESS 0x52



int counter;


uint8_t data[6];

void setup()
{

servo1.attach(11);
servo2.attach(12);


Wire.begin();

Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0xF0);
Wire.write(0x55);
Wire.endTransmission();

Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0xFB);
Wire.write(0x00);
Wire.endTransmission();
}

void loop()
{

Wire.requestFrom(WII_NUNCHUK_I2C_ADDRESS, 6);

counter = 0;

while(Wire.available())
{

data[counter++] = Wire.read();
}


Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0x00);
Wire.endTransmission();

if(counter >= 5)
{

double accelX = ((data[2] << 2) + ((data[5] >> 2) & 0x03) - ZEROX);
double accelY = ((data[3] << 2) + ((data[5] >> 4) & 0x03) - ZEROY);
double accelZ = ((data[4] << 2) + ((data[5] >> 6) & 0x03) - ZEROZ);

int value = constrain(accelY, -180, 180);

value = map(value, -180, 180, 0, 180);

servo1.write(value);


value = constrain(accelX, -180, 180);
value = map(value, -180, 180, 0, 180);
servo2.write(value);


delay(20);
}
}

0
RomainB5
RomainB5

5 years ago

I made it ! Very cool & fun !

But... Same question as @Alienpuppy : can you explain the setup ?

Thanks !

0
n-veira
n-veira

5 years ago

Just made it! thanks only issiue that i had when i groundeed out the wii remote on the breadboard, the servos would pickup some sort of interferance. i just groiunded out on the board seems to work fine!

0
Alienpuppy
Alienpuppy

5 years ago

This is great! I want to try it out.

One question... I don't understand the setup() part of the code. Can you explain the values you write to the nunchuk when it is initialized... I'm assuming it is some initialization protocol, but it differs from another one I found on the web.
Do you have a nunchuk protocol document you could share?

This is the one I found:
http://www.robotshop.com/media/files/PDF/inex-zx-n...

It says to write 0x40 and 0x00 to initialize.
Your code writes 0xF0 and 0x55... followed by 0xFB and 0x00.

Thanks!

0
BoianM
BoianM

5 years ago

Cool! After seeing this, I added support for Wii Nunchuck in Visuino, and included similar Demo project :-)
Thank you for the great idea!

0
mde bont
mde bont

Reply 5 years ago

Given him then also a free version of your software ;-)

0
BoianM
BoianM

Reply 5 years ago

You can always run Visuino for 5 minutes at a time, which is actually more than enough time to make this project ;-)

0
BoianM
BoianM

Reply 5 years ago

And if he contact me, I will give him a free version :-)

0
GeekMomProjects
GeekMomProjects

5 years ago

Nice work - I've done a similar project. The servos will be less jittery if you give them a separate power supply from the Arduino.