Project tutorial

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO © GPL3+

Do you know of the famous WS1012 LEDs? The PL9823 is the cheapest LED that uses the same protocol of the WS1012. Let's blink LEDs!

  • 836 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
(optional)

Apps and online services

About this project

If you know of the famous WS1012 LEDs, you can't ignore this tutorial. The PL9823 is the cheapest LED that uses the same protocol of the WS1012 LED. You can use this LED to make an LED strip or even an LED matrix. PIX is an LED matrix made with WS1012 matrix. This matrix uses 64 WS1012 LEDs. But in this tutorial, we are going to create a simple and efficient "knight ride" with PL9823 LEDs and Arduino UNO.

Step 1: Materials

All the materials are:

If you want make a PL9823 strip board, you'll also need:

Step 2: Assembly the circuit

You can see the circuit in the image. Pay attention to the PL9823 LED models. If you use a F-8 model (see the image), you can use the long one pin like GND. If you use the F-5 model, the GND is the second one long pin. Take care and pay attention to the VCC pin and GND pin. You can burn and break the LED immediately if you connect the pin GND to VCC and vice versa. After this you can connect the communication pin. Use DIN for Arduino UNO signal, and DO to pass the signal to other PL9823 LED.

You can use thousand of LEDs.

Step 3: Library and code

First is to import the Adafruit Neopixel library. See the Adafruit Github page or Adafruit site page for direct download and installation info. Put the library in the library folder in the Arduino project folder.

After download the PL9823 file and upload to the Arduino UNO. As you can see by the code, the most important thing is the line:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_RGB + NEO_KHZ400);

The NEO_GBR is for the WS2812b LED models, the NEO_RGB is for this model. The velocity of communication is NEO_KHZ400, for the WS2812 is 800.

Step 4: Final result

Now you have a multicolor Knight Ride. You can solder the LEDs on the perfboard like in the photo.

Code

Arduino Knight Rider PL9823 LEDArduino
// PL9823 Knight Night
// November 2015
// Creative Common License
// www.0lab.it

#include <Adafruit_NeoPixel.h>

// SETUP YOUR OUTPUT PIN AND NUMBER OF PIXELS
#define PIN 6
#define NUM_PIXELS  5
#define vel 100 // Velocity in milliseconds

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_RGB + NEO_KHZ400);

void setup() {
  strip.begin();
  clearStrip(); // Initialize all pixels to 'off'
  delay(1000);
}

void loop() {
  knightRider(3, vel, 4, 0xFF1000); // Cycles, Speed, Width, RGB Color (original orange-red)
  knightRider(3, vel, 3, 0xFF00FF); // Cycles, Speed, Width, RGB Color (purple)
  knightRider(3, vel, 2, 0x0000FF); // Cycles, Speed, Width, RGB Color (blue)
  knightRider(3, vel, 5, 0xFF0000); // Cycles, Speed, Width, RGB Color (red)
  knightRider(3, vel, 6, 0x00FF00); // Cycles, Speed, Width, RGB Color (green)
  knightRider(3, vel, 7, 0xFFFF00); // Cycles, Speed, Width, RGB Color (yellow)
  knightRider(3, vel, 8, 0x00FFFF); // Cycles, Speed, Width, RGB Color (cyan)
  knightRider(3, vel, 2, 0xFFFFFF); // Cycles, Speed, Width, RGB Color (white)
  clearStrip();
  delay(2000);

  // Iterate through a whole rainbow of colors
  for(byte j=0; j<252; j+=7) {
    knightRider(1, vel, 2, colorWheel(j)); // Cycles, Speed, Width, RGB Color
  }
  clearStrip();
  delay(2000);
}

// Cycles - one cycle is scanning through all pixels left then right (or right then left)
// Speed - how fast one cycle is (32 with 16 pixels is default KnightRider speed)
// Width - how wide the trail effect is on the fading out LEDs.  The original display used
//         light bulbs, so they have a persistance when turning off.  This creates a trail.
//         Effective range is 2 - 8, 4 is default for 16 pixels.  Play with this.
// Color - 32-bit packed RGB color value.  All pixels will be this color.
// knightRider(cycles, speed, width, color);
void knightRider(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) {
  uint32_t old_val[NUM_PIXELS]; // up to 256 lights!
  // Larson time baby!
  for(int i = 0; i < cycles; i++){
    for (int count = 1; count<NUM_PIXELS; count++) {
      strip.setPixelColor(count, color);
      old_val[count] = color;
      for(int x = count; x>0; x--) {
        old_val[x-1] = dimColor(old_val[x-1], width);
        strip.setPixelColor(x-1, old_val[x-1]); 
      }
      strip.show();
      delay(speed);
    }
    for (int count = NUM_PIXELS-1; count>=0; count--) {
      strip.setPixelColor(count, color);
      old_val[count] = color;
      for(int x = count; x<=NUM_PIXELS ;x++) {
        old_val[x-1] = dimColor(old_val[x-1], width);
        strip.setPixelColor(x+1, old_val[x+1]);
      }
      strip.show();
      delay(speed);
    }
  }
}

void clearStrip() {
  for( int i = 0; i<NUM_PIXELS; i++){
    strip.setPixelColor(i, 0x000000); strip.show();
  }
}

uint32_t dimColor(uint32_t color, uint8_t width) {
   return (((color&0xFF0000)/width)&0xFF0000) + (((color&0x00FF00)/width)&0x00FF00) + (((color&0x0000FF)/width)&0x0000FF);
}

// Using a counter and for() loop, input a value 0 to 251 to get a color value.
// The colors transition like: red - org - ylw - grn - cyn - blue - vio - mag - back to red.
// Entering 255 will give you white, if you need it.
uint32_t colorWheel(byte WheelPos) {
  byte state = WheelPos / 21;
  switch(state) {
    case 0: return strip.Color(255, 0, 255 - ((((WheelPos % 21) + 1) * 6) + 127)); break;
    case 1: return strip.Color(255, ((WheelPos % 21) + 1) * 6, 0); break;
    case 2: return strip.Color(255, (((WheelPos % 21) + 1) * 6) + 127, 0); break;
    case 3: return strip.Color(255 - (((WheelPos % 21) + 1) * 6), 255, 0); break;
    case 4: return strip.Color(255 - (((WheelPos % 21) + 1) * 6) + 127, 255, 0); break;
    case 5: return strip.Color(0, 255, ((WheelPos % 21) + 1) * 6); break;
    case 6: return strip.Color(0, 255, (((WheelPos % 21) + 1) * 6) + 127); break;
    case 7: return strip.Color(0, 255 - (((WheelPos % 21) + 1) * 6), 255); break;
    case 8: return strip.Color(0, 255 - ((((WheelPos % 21) + 1) * 6) + 127), 255); break;
    case 9: return strip.Color(((WheelPos % 21) + 1) * 6, 0, 255); break;
    case 10: return strip.Color((((WheelPos % 21) + 1) * 6) + 127, 0, 255); break;
    case 11: return strip.Color(255, 0, 255 - (((WheelPos % 21) + 1) * 6)); break;
    default: return strip.Color(0, 0, 0); break;
  }
}
Adafruit neopixel library
https://github.com/adafruit/Adafruit_NeoPixel

Comments

Similar projects you might like

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 244 views
  • 0 comments
  • 5 respects

Development Board for AtTiny MCU

by Vincenzo G.

  • 100 views
  • 0 comments
  • 4 respects

Version 2.0 Advanced Attendance System (Without Ethernet)

Project tutorial by GadgetProgrammers

  • 2,902 views
  • 5 comments
  • 44 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 145 views
  • 0 comments
  • 3 respects

Ultrasonic Security System

Project tutorial by Krepak

  • 354 views
  • 0 comments
  • 6 respects
Add projectSign up / Login