Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Eben Kouao
Published © GPL3+

DIY Electric Skateboard – Using Arduino LEDs

How to build a DIY Electric Skateboard faster than one you can buy, using an Arduino Nano to control the programmable lights.

AdvancedFull instructions provided7 hours11,784
DIY Electric Skateboard – Using Arduino LEDs

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
LED Strip, NeoPixel Digital RGB
LED Strip, NeoPixel Digital RGB
×1
Longboard
×1
Brushless Motor (Flipsky 190 KV)
×1
VESC (Electronic Speed Controller)
×1
2 x LiPo Batteries (5000 mAh 5S)
×1
2.4 GHz Remote & Receiver
×1
JLCPCB Customized PCB
JLCPCB Customized PCB
You can also make a final PCB version of an Arduino shield for the LEDs.
×1

Software apps and online services

Arduino IDE
Arduino IDE
VECS BLDC Tool

Story

Read more

Code

Arduino NeoPixel Skateboard Lights

C/C++
This code would light up the NeoPixels - which can be programmed to any hue or color.
/*
 * Example Library: Arduino NeoPixel
 * Modified by Eben - smartbuilds.io
 * Date: 29.08.20
 * 
 * Description: Adopted Neopixel example libarary for the Electric Skateboard LED lights
 * This example lights up the front and break lights for the LED.
 * Push buttons can be put on Pin 10 and 11 for indicator lights. More info: smartbuilds.io
 */

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6
int potPin = 2;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the sensor
#define ledPin 9
char state = (int) 0;
const int buttonPinL = 10;     // the number of the pushbutton pin
const int buttonPinR = 11;     // the number of the pushbutton pin

// variables will change:
int buttonStateL = 0;         // variable for reading the pushbutton status


// variables will change:
int buttonStateR = 0;         // variable for reading the pushbutton status


// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_Left = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800); //Left


// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first. 

void setup() {
  Serial.begin(9600); // open the serial port at 9600 bps:
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);

   // initialize the pushbutton pin as an input:
  pinMode(buttonPinL, INPUT);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPinR, INPUT);

  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code


  strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  //Electric Skateboard Break Lights
  breakLights(strip.Color(255, 0, 0), 50);

  //Electric Skateboard Front Lights
  frontLights(strip.Color(127, 127, 127), 50);

 
  // read the state of the pushbutton value: --> Only if you're using a Push Button for indicator lights
  buttonStateL = digitalRead(buttonPinL);

  // read the state of the pushbutton value: --> Only if you're using a Push Button for indicator lights
  buttonStateR = digitalRead(buttonPinR);


  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonStateL == HIGH) {
    // turn LED on:
    colorWipe_Left(strip.Color(255, 100, 0), 50);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }



   // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonStateR == HIGH) {
    // turn LED on:
    
    colorWipe_Right(strip.Color(255, 100, 0), 50); // Red
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }

}



// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
 
}


// Fill the dots one after the other with a color
void frontLights(uint32_t c, uint8_t wait) {
    //strip.setPixelColor(48, c);
    //strip.setPixelColor(49, c);
    //strip.setPixelColor(50, c);
    strip.setPixelColor(21, c);
    strip.setPixelColor(22, c);
    strip.setPixelColor(24, c);
    strip.setPixelColor(25, c);
    //strip.setPixelColor(55, c);
    //strip.setPixelColor(56, c);
    //strip.setPixelColor(57, c);
    //strip.setPixelColor(58, c);
    //strip.setPixelColor(59, c);
    strip.show();
    delay(wait);
 
}

// Fill the dots one after the other with a color
void breakLights(uint32_t c, uint8_t wait) {
    //strip.setPixelColor(48, c);
    //strip.setPixelColor(49, c);
    //strip.setPixelColor(50, c);
    strip.setPixelColor(51, c);
    strip.setPixelColor(52, c);
    strip.setPixelColor(53, c);
    strip.setPixelColor(54, c);
    strip.setPixelColor(55, c);
    strip.setPixelColor(56, c);
    //strip.setPixelColor(57, c);
    //strip.setPixelColor(58, c);
    //strip.setPixelColor(59, c);
    strip.show();
    delay(wait);
 
}

// Fill the dots one after the other with a color
void colorWipe_Brake(uint32_t c, uint8_t wait) {
    strip.setPixelColor(48, c);
    strip.setPixelColor(49, c);
    strip.setPixelColor(50, c);
    strip.setPixelColor(51, c);
    strip.setPixelColor(52, c);
    strip.setPixelColor(53, c);
    strip.setPixelColor(54, c);
    strip.setPixelColor(55, c);
    strip.setPixelColor(56, c);
    strip.setPixelColor(57, c);
    strip.setPixelColor(58, c);
    strip.setPixelColor(59, c);
    strip.show();
    delay(wait);
 
}

// Fill the dots one after the other with a color
void colorWipe_Reverse(uint32_t c, uint8_t wait) {
    strip.setPixelColor(48, c);
    strip.setPixelColor(49, c);
    strip.setPixelColor(50, c);
    strip.setPixelColor(51, c);
    strip.setPixelColor(52, c);
    strip.setPixelColor(53, c);
    strip.setPixelColor(54, c);
    strip.setPixelColor(55, c);
    strip.setPixelColor(56, c);
    strip.setPixelColor(57, c);
    strip.setPixelColor(58, c);
    strip.setPixelColor(59, c);
    strip.show();
    delay(wait);
 
}

// Fill the dots one after the other with a color
void colorWipe_Left(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < (strip.numPixels()-40); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);

    strip.setPixelColor(21, c);
    strip.setPixelColor(22, c);

   for (uint16_t i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, 0);      //turn every third pixel off
      }

  }

      
}

// Fill the dots one after the other with a color
void colorWipe_Right(uint32_t c, uint8_t wait) {
  for (uint16_t i = 46; i > (strip.numPixels()-37); i--) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);

        strip.setPixelColor(24, c);
    strip.setPixelColor(25, c);

  for (uint16_t i = 46; i > strip.numPixels()-36; i--) {
        strip.setPixelColor(i, 0);      //turn every third pixel off
      }

   strip.setPixelColor(i, 0);      //turn every third pixel off
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j = 0; j < 256; j++) {   // cycle all 256 colors in the wheel
    for (int q = 0; q < 3; q++) {
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Github file

https://github.com/rpasichnyk/vesc_tool/releases

Credits

Eben Kouao

Eben Kouao

5 projects • 64 followers
I like to build stuff.

Comments