Arduino Wii Nunchuck Controller

16,016

306

15

How to control 2 servos thought the wii nunchuck.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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!!

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    15 Discussions

    0
    None
    Alexan24NoahTube HD

    Answer 1 year 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
    None
    RoccoV3

    3 years ago

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

    1 reply
    0
    None
    Alexan24RoccoV3

    Reply 3 years ago

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

    0
    None
    aaron2016

    3 years ago

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

    1 reply
    0
    None
    Alexan24aaron2016

    Reply 3 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
    None
    RomainB5

    3 years ago

    I made it ! Very cool & fun !

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

    Thanks !

    0
    None
    n-veira

    3 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
    None
    Alienpuppy

    3 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
    None
    BoianM

    3 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!

    3 replies
    0
    None
    mde bontBoianM

    Reply 3 years ago

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

    0
    None
    BoianMmde bont

    Reply 3 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
    None
    BoianMBoianM

    Reply 3 years ago

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

    0
    None
    GeekMomProjects

    3 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.