Electric Skateboard - Universal bluetooth remote + HC-05 + Arduino Uno R3

Hello Everyone,

Very new to the Arduino community. I've been laying the ground work for developing an electric skateboard and after research and consideration, I would like to use an arduino uno + HC-05 bluetooth module + a "universal" bluetooth game controller to control the ESC that controls the brushless motor and drives the skateboard. People that use the arduino uno as a tx/rx board typically use a wireless Wii nunchuck or an app. The Wii nunchuck is a bit more pricey than just buying a universal bluetooth controller. To save a few extra bucks on the project, I was wondering if the coding for a universal bluetooth controller would be significantly different than the coding for the Wii nunchuck?

Code for Wii nunchuck (credit to Rahul Iyer for the code):

/*

  • Rahul Iyer
    */

#include <Servo.h>
#include <Wire.h>
#include <ArduinoNunchuk.h>

#define BAUDRATE 19200

#define CHUCK_ZERO 133
#define CHUCK_MAX 255
#define ESC_ZERO 90
#define SPEED_MAX 130

ArduinoNunchuk nunchuk = ArduinoNunchuk();

int escOutputValue = ESC_ZERO;
float currentOutputValue = ESC_ZERO;

int resetCounter = 0;
Servo ESC;

void setup()
{
ESC.attach(9);
Serial.begin(BAUDRATE);

nunchuk.init();
delay(100);
}

void loop()
{

resetCounter++;

if (resetCounter==40)
{
resetCounter=0;
nunchuk.init();
delay(100);
}

nunchuk.update();

// Serial.print(nunchuk.analogX, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.analogY, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.accelX, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.accelY, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.accelZ, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.zButton, DEC);
// Serial.print(' ');
// Serial.print(nunchuk.cButton, DEC);
// Serial.print(' ');

int yValue = nunchuk.analogY;

if (yValue<CHUCK_ZERO)
{
yValue = CHUCK_ZERO; // no backwards
}

// escOutputValue = map(yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX); //linear relationship between joystick value and ESC output value--deemed not good enough :stuck_out_tongue:

if (yValue == CHUCK_ZERO)
{
escOutputValue = ESC_ZERO; //if joystick is at zero, no power to motor (coast)
currentOutputValue = ESC_ZERO; //reset
}
else
{
int maxPossibleSpeed = map (yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX);

if (escOutputValue > maxPossibleSpeed)
{
escOutputValue = maxPossibleSpeed;
}
else
{
float increment = (1.0 * (yValue - CHUCK_ZERO)) / (CHUCK_MAX - CHUCK_ZERO);

currentOutputValue += increment;
escOutputValue = (int) currentOutputValue;

if (escOutputValue > maxPossibleSpeed)
{
escOutputValue = maxPossibleSpeed;
}
}
}

ESC.write(escOutputValue);
Serial.println(escOutputValue); //for debugging
}

Also, would the wiring be the same (Please see attachment for diagram)?

Does your ESC have a BEC? Is it 5V? Why feed it to Vin?