Project tutorial
LED Emergency Lights using WS2812 RGB LED Module

LED Emergency Lights using WS2812 RGB LED Module

LED emergency lights for use on model / toy vehicles and other projects. Uses Arduino UNO and GY-WS2812B-8 RGB LED Module from DIYmall.

  • 12,700 views
  • 7 comments
  • 30 respects

Components and supplies

About this project

Background

The purpose of this project is to show how you can use a WS2812 RGB LED Module to do some emergency lights for things like model cars.  It could likely be used for other projects, but I would recommend not using this in your vehicle unless you have checked local laws and have a legal/valid reason to do so.  The specific module I used has model # GY-WS2812B-8 on the back and comes from DIYmall.


Setup - Hardware

The setup is pretty simple.  The model needs to have wires or pin header soldered to it, I used a pin header for testing but for an actual project you should consider soldering wires.

Unless you are using a board that can handle high current load, you will want to use a separate power supply for the LEDs (which you will probably need anyways to supply power to your microcontroller).

The GY-WS2812B-8 board has 4 solder pads on each side.  Make sure you use the side that has "DIN" for data in, the other side has "DOUT" which would feed the next module if you daisy chain them.

Here is how I wired mine:

- Connect the ground for the LED module, UNO and power supply together
- Connect the + of your 5V power supply to "4-7VDC" on the LED module and VIN on the UNO
- Connect "DIN" on the LED module to PIN 6 on the UNO (for the data)


NOTE: The sample code recommends the use of a resistor and capacitor, I didn't for these simple tests but I would recommend considering those additional components.


Setup - Software

For software, I used the Adafruit NeoPixel library ( https://github.com/adafruit/Adafruit_NeoPixel ).  It includes a "standtest" sample, which is what I used as a starting point for my code.  I would recommend you look over the sample code, and try it out.

I modified the code to setup some different LED patterns that an emergency vehicle would likely use.  The patterns I setup do the following:

ArrowLeft and ArrowRight - These make the lights point left or right (depending on how you have the board mounted, it might seem backwards).

WigWag - This does a typical left/right strobe that emergency services would use

WigWag2 - This allows you to use different colors on each size

BlinkOuter - This blinks to two outer LEDs

OnOuter - This turns the two outer LEDs on

ClearLights - This turns off all the LEDs


Showing off various patterns

My sample code runs through a few variations of each pattern, to give you a starting point to modify the code to meet your needs.  I left much of the original comments in the code (from the sample code I used) and I also added extra comments to help explain my own code.


Wrap Up

Overall, this would be a neat addition to any model vehicle (emergency services or construction) and could even be used for other projects ( safety light for a bike for example ).



Code

UNO CodeC/C++
Use with GY-WS2812B-8 board
/*
 * NOTE: The code below is based on the "strandtest" example that comes with
 * the Adafruit NeoPixel library.  I left in most of the original comments.
 */

// Left as-is from the example
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6

// All of this stuff below is from the example
// 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

//NOTE: I tested this code with an 8 LED module, but you should be able to daisy chain multiple modules
//NOTE: Try changing the "8" to "4" to see how it reacts.

// This warning is from the example, probably worth considering
// 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() {
  // This stuff is from the example, I commented it out since I am not using a Trinket
  // 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.show();
}

void loop() {
  /*
   * For strip.Color(R, G, B), use 0-255 to set intensity
   * for each color (R)ed, (G)reen, (B)lue
   *
   * The last number is a delay 0-255 range.
   */

  // These are left/right signals
  ArrowLeft(strip.Color(0, 0, 255), 100); // Blue
  ArrowRight(strip.Color(255, 0, 0), 200); //Red

  // These are side to side or wig/wag
  WigWag(strip.Color(255, 0, 0), 200); // Red
  WigWag(strip.Color(0, 0, 255), 63); // Blue faster
  WigWag(strip.Color(0, 0, 255), 127); // Blue medium
  WigWag(strip.Color(0, 0, 255), 255); // Blue slowest
  WigWag(strip.Color(0, 255, 0), 200); // Green
  WigWag(strip.Color(255, 255, 0), 200); // Yellow
  ClearLights();
  delay(1000);
  // This is a 2 color wigwag
  WigWag2(strip.Color(0, 0, 255), strip.Color(255, 0, 0), 200); // Blue and Red
  ClearLights();
  delay(1000);

  // Blinks the outer most lights
  BlinkOuter(strip.Color(0, 0, 255), 200); //Blue
  BlinkOuter(strip.Color(0, 0, 255), 50); //Blue faster
  BlinkOuter(strip.Color(255, 255, 0), 200); //Yellow
  ClearLights();
  delay(1000);

  // Turns the outer most lights on
  OnOuter(strip.Color(63, 0, 0)); // Red 25%
  OnOuter(strip.Color(127, 0, 0)); // Red 50%
  OnOuter(strip.Color(191, 0, 0)); // Red 75%
  OnOuter(strip.Color(255, 0, 0)); // Red 100%
  ClearLights();
  delay(1000);
  OnOuter(strip.Color(0, 0, 255)); // Blue
  OnOuter(strip.Color(0, 255, 0)); // Green
  // Turns off all lights
  ClearLights();
  delay(5000);
}

void ArrowRight(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 4; j++) { // The j<# determines how many cycles
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);
  }
}

void ArrowLeft(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 4; j++) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
    for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);
  }
}

void WigWag(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { // The j<# determines how many cycles
    for (int i = 0; i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, c);
    }
    for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);

    for (int i = 0; i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, 0);
    }
    for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, c);
    }
    strip.show();
    delay(wait);
  }
}


void WigWag2(uint32_t c, uint32_t c2, uint8_t wait) {
  for (int j = 0; j < 20; j++) { // The j<# determines how many cycles
    for (int i = 0; i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, c);
    }
    for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);

    for (int i = 0; i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, 0);
    }
    for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
      strip.setPixelColor(i, c2);
    }
    strip.show();
    delay(wait);
  }
}

void ClearLights() {
  for (int i = 0; i < strip.numPixels(); i = i + 1) {
    strip.setPixelColor(i, 0);    //turn every pixel off
  }
  strip.show();
}

void BlinkOuter(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { // The j<# determines how many cycles
    strip.setPixelColor(strip.numPixels() - 1, c);
    strip.setPixelColor(0, c);
    strip.show();
    delay(wait);
    strip.setPixelColor(strip.numPixels() - 1, 0);
    strip.setPixelColor(0, 0);
    strip.show();
    delay(wait);
  }
}

void OnOuter(uint32_t c) {
  strip.setPixelColor(strip.numPixels() - 1, c);
  strip.setPixelColor(0, c);
  strip.show();
  delay(3000);
}

Comments

Similar projects you might like

LED Blink Pattern

Project tutorial by Matt Arnold

  • 30,339 views
  • 14 comments
  • 84 respects

Automated Staircase RGB LED Lights

Project tutorial by Team NotEnoughTech.com

  • 27,609 views
  • 19 comments
  • 98 respects

Music Adaptive RGB LED with Arduino and Processing

Project in progress by ounane mohamed elfarouk

  • 2,953 views
  • 8 comments
  • 24 respects

Control a RGB Led using Arduino and a smartphone's camera

Project tutorial by Mr robot Maker

  • 2,860 views
  • 0 comments
  • 8 respects

Kids RGB LED Star Nightlight

Project tutorial by Unexpected Maker

  • 2,524 views
  • 1 comment
  • 14 respects
Add projectSign up / Login