loading

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

<p>ciao ho provato il codice... avrei una domanda come faccio funzionare i due servo con il joy senza muovere il telecomando ?</p>
<p>Non riesco a capire quello che voglio dire.Prova a scrivere in inglese.</p>
<p>I can't download the code, can u just write it on step #3</p>
<p>Here you are!!</p><p><br>#include &lt;Servo.h&gt;<br>Servo servo1; <br>Servo servo2;<br>#include &lt;Wire.h&gt;<br><br><br>#define ZEROX 530 <br>#define ZEROY 530<br>#define ZEROZ 530<br><br><br>#define WII_NUNCHUK_I2C_ADDRESS 0x52<br><br><br><br>int counter;<br><br><br>uint8_t data[6];<br><br>void setup() <br>{ <br> <br> servo1.attach(11);<br> servo2.attach(12);<br><br> <br> Wire.begin();<br><br> Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);<br> Wire.write(0xF0);<br> Wire.write(0x55);<br> Wire.endTransmission();<br><br> Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);<br> Wire.write(0xFB);<br> Wire.write(0x00);<br> Wire.endTransmission();<br>} <br><br>void loop() <br>{ <br> <br> Wire.requestFrom(WII_NUNCHUK_I2C_ADDRESS, 6);<br><br> counter = 0;<br> <br> while(Wire.available())<br> {<br> <br> data[counter++] = Wire.read();<br> }<br><br> <br> Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);<br> Wire.write(0x00);<br> Wire.endTransmission();<br><br> if(counter &gt;= 5)<br> {<br> <br> double accelX = ((data[2] &lt;&lt; 2) + ((data[5] &gt;&gt; 2) &amp; 0x03) - ZEROX);<br> double accelY = ((data[3] &lt;&lt; 2) + ((data[5] &gt;&gt; 4) &amp; 0x03) - ZEROY);<br> double accelZ = ((data[4] &lt;&lt; 2) + ((data[5] &gt;&gt; 6) &amp; 0x03) - ZEROZ);<br><br> int value = constrain(accelY, -180, 180);<br> <br> value = map(value, -180, 180, 0, 180);<br> <br> servo1.write(value);<br> <br> <br> value = constrain(accelX, -180, 180);<br> value = map(value, -180, 180, 0, 180); <br> servo2.write(value);<br><br> <br> delay(20);<br> }<br>}</p>
<p>I made it ! Very cool &amp; fun !</p><p>But... Same question as @Alienpuppy : can you explain the setup ?</p><p>Thanks !</p>
<p>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!</p>
<p>This is great! I want to try it out.<br><br>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.<br>Do you have a nunchuk protocol document you could share?<br><br>This is the one I found:<br><a href="http://www.robotshop.com/media/files/PDF/inex-zx-nunchuck-datasheet.pdf" rel="nofollow">http://www.robotshop.com/media/files/PDF/inex-zx-n...</a><br><br>It says to write 0x40 and 0x00 to initialize.<br>Your code writes 0xF0 and 0x55... followed by 0xFB and 0x00.<br><br>Thanks!<br></p>
<p>Cool! After seeing this, I added support for Wii Nunchuck in Visuino, and included similar Demo project :-)<br>Thank you for the great idea!</p>
<p>Given him then also a free version of your software ;-)</p>
<p>You can always run Visuino for 5 minutes at a time, which is actually more than enough time to make this project ;-)</p>
<p>And if he contact me, I will give him a free version :-)</p>
<p>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.</p>
<p>Fun way to control an Arduino project.</p>

About This Instructable

12,763views

295favorites

License:

More by Alexan24:Wi-Fi Jammer Using ESP8266-01? Lock your door with a remote control?? DIY Arduino Weather Station 
Add instructable to: