Wii Nunchuck Controlled ESC

This is my electronics setup for my electric longboard that I am building. These parts cost me about 157$ not including the stuff I already had.
My project is documented @ http://www.afchacks.wordpress.com along with the code for the arduino.

You’ll need the WiiChuck.h library and the Wii.h library for this to work. Contact me and ill send them to. I can make a tutorial video upon request.

Source Code( With braking)

#include “Wire.h”
#include “WiiChuck.h” // Library for Wii Nunchuck
#include “Wii.h”
#include <ArduinoNunchuk.h>
#include <Servo.h> // Library for controlin Servo or ESC
WiiChuck chuck = WiiChuck();
Servo myservo;
int speed_val; // Speed value
int speed_val_cur = 95; // Current speed value
int y = 0; // Jaystick value
int time = 200; // Delay timer
int speed_val_hold; // speed value which will be holded while Z button is pressed

void setup() {

Serial.begin(115200);
chuck.begin();
chuck.update();
myservo.attach(9); // ESC attached to 9 pin of Arduino

}

void loop() {

// If you hold down Z button of Nunchuck you accelerate faster
if ((chuck.buttonZ)||(chuck.buttonC)) {
if (chuck.buttonZ) {
Serial.print(” Z “);
time = 100;
speed_val_hold = speed_val_cur; // Sets speed value to hold
}
// If you hold down C button of Nunchuck you accelerate slower
if (chuck.buttonC) {
Serial.print(” C “);
//time = 100;
}
} else {
time = map (speed_val_cur,60,80,100,250);
speed_val_hold = 95;
}

delay(time);

chuck.update();
y = chuck.readJoyY();

// Maps the joystick value to the speed value (max speed 130) max posible 179
Serial.println();
speed_val = map(y, -105, 73, 95, 140);
// This is what hapens in case we loose a Blue tooth conecction
if (y > 122) {
speed_val = 95; // 60 means – no speed , motor stoped
speed_val_cur = 95; // 60 means – no speed , motor stoped
speed_val_hold = 95;
}
// This is whats hapens then we again have BT signal, it just restarts everything
if (y == 124) setup();

if (y <= 0) {
speed_val_cur = 95;
speed_val = 95;

}
if (speed_val_cur < speed_val) {

speed_val_cur = speed_val_cur + 1;

}
else speed_val_cur = speed_val;

if ((speed_val_hold > 95) && (y > 0) ) speed_val_hold++; // If hold button is pressed and joistic moved up – increase speed
if ((speed_val_hold > 95) && (y < 0) ) speed_val_hold–; // If hold button is pressed and joistic moved down – decrease speed

if (speed_val_hold > 95) speed_val_cur = speed_val_hold;
if (chuck.buttonC) {
speed_val_cur = 60;
//time = 100;
}
myservo.write(speed_val_cur); // Here we control ESC
//—– Printing to screen to see results ———
Serial.print(“Joy = “);
Serial.print(y);
Serial.print(” “);
Serial.print(“Speed = “);
Serial.print(speed_val_cur);
}

Original Code by Mantas

Edited by Airfield20

About these ads

9 responses to “Wii Nunchuck Controlled ESC

  1. Explain why everyone is using motors around 2kw for their boards if most common electric skateboards selling runs around 600 to 800 watts that is around 1hp ? I build mine with what I can reach here in Rio ! Was a Sk3542 1250kv 700w but unfortunately the ratio I’ve got was a 2/1 I did get a pretty nice speed out of the motor but I burn my esc in 3km run with few stops !

  2. Hello, first of all, nice build. And a lot of good information!

    Coud you also send me the Wiichuck.h and Wii.h files to me?

    My mail is remia 1 frietsaus@hotmail.com offcourse without the space before and after the one.

    Tanks you so far, and keep up the good work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s