I have seen many people showing LED Strip on YouTube with bright colours and the colours fast changes in many different ways. Those LED Strips were spectacular!! So, I think I should try this out myself. After few searches on the internet, I quickly discover the name of this LED strips are called WS2812 or WS1812B 5050. They are widely available on auction sites.
Material needed for this tutorial:
- W2812B LED Strip 60 LED per meter, 5V/3A (I bought 2 meters)
I bought water resistant which it has transparent covers on the whole strip. - Arduino Mini Pro * 1
- Few jump wires
- Power source for the LED Strip (Adapter or battery pack)
- Arduino pin 6 to W2812B data pin
- Arduino +5V to power source 5V
- Arduino GND to power source GND
- W2812B +5V to +5V power 5V/3A adapter (Power needed depends on how many LED you hook up)
- W2812B GND to power 5V/3A adapter GND
- Arduino GND to W2812B GND
For more advanced control, you definitely want to visit FastLED Wiki to get more information.
1. LED_PIN = I use pin 6
2. NUM_LEDS = I have 120 in my LED Strip
Here is the source code:
#include <FastLED.h> #include#define LED_PIN 6 // Information about the LED strip itself #define NUM_LEDS 120 #define CHIPSET WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define BRIGHTNESS 128 // FastLED v2.1 provides two color-management controls: // (1) color correction settings for each LED strip, and // (2) master control of the overall output 'color temperature' // // THIS EXAMPLE demonstrates the second, "color temperature" control. // It shows a simple rainbow animation first with one temperature profile, // and a few seconds later, with a different temperature profile. // // The first pixel of the strip will show the color temperature. // // HELPFUL HINTS for "seeing" the effect in this demo: // * Don't look directly at the LED pixels. Shine the LEDs aganst // a white wall, table, or piece of paper, and look at the reflected light. // // * If you watch it for a bit, and then walk away, and then come back // to it, you'll probably be able to "see" whether it's currently using // the 'redder' or the 'bluer' temperature profile, even not counting // the lowest 'indicator' pixel. // // // FastLED provides these pre-conigured incandescent color profiles: // Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc, // HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky, // FastLED provides these pre-configured gaseous-light color profiles: // WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent, // FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent, // MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium, // FastLED also provides an "Uncorrected temperature" profile // UncorrectedTemperature; #define TEMPERATURE_1 Tungsten100W #define TEMPERATURE_2 OvercastSky // How many seconds to show each temperature before switching #define DISPLAYTIME 20 // How many seconds to show black between switches #define BLACKTIME 3 void loop() { // draw a generic, no-name rainbow static uint8_t starthue = 0; fill_rainbow( leds + 5, NUM_LEDS - 5, --starthue, 20); // Choose which 'color temperature' profile to enable. uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2); if( secs < DISPLAYTIME) { FastLED.setTemperature( TEMPERATURE_1 ); // first temperature leds[0] = TEMPERATURE_1; // show indicator pixel } else { FastLED.setTemperature( TEMPERATURE_2 ); // second temperature leds[0] = TEMPERATURE_2; // show indicator pixel } // Black out the LEDs for a few secnds between color changes // to let the eyes and brains adjust if( (secs % DISPLAYTIME) < BLACKTIME) { memset8( leds, 0, NUM_LEDS * sizeof(CRGB)); } FastLED.show(); FastLED.delay(8); } void setup() { delay( 3000 ); // power-up safety delay // It's important to set the color correction for your LED strip here, // so that colors can be more accurately rendered through the 'temperature' profiles FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); FastLED.setBrightness( BRIGHTNESS ); }
Now compile and upload to Arduino Pro Mini through Arduino IDE and you will sett LED strips light up after few seconds. It's really nice, isn't it!!
Here is the W2812B in motion.
Although it is so easy to light it up, my final goal is to make a Lightsaber with this LED strip. With the MP3 module I tested before, I wish I can put these two together without any issue.
Let's see if would able to do that!
Done.
============================================================
測試 WS2812B LED 燈條
常在網路上看到許多人秀出彩色的LED燈條,不但能顯示出各種顏色還能做出千變萬化的效果! 經過一番網路搜尋,原來這燈條叫做 WS1812B 5050(我還是不知道5050的由來,知道的再告訴我)。於是我上網拍去買了2公尺燈條,現在動手來試試吧!
做這個實驗所需的材料如下:
- W2812B LED 燈條 60 LED/公尺 , 5V/3A (我買了2公尺)
燈條有分防水和不防水的,你可以依自己的喜好做選擇。 - Arduino Mini Pro * 1
- 跳線數條
- 5V or 12V 電源/電池
- Arduino pin 6 to W2812B data pin
- Arduino +5V to power source 5V
- Arduino GND to power source GND
- W2812B +5V to +5V power 5V/3A adapter (Power needed depends on how many LED you hook up)
- W2812B GND to power 5V/3A adapter GND
- Arduino GND to W2812B GND
2. NUM_LEDS = LED 串聯的總顆數,我的是 120 顆
接下來只要編譯再傳到 Arduino Pro Mini,2 秒後就可以看到燈條亮起來了!真漂亮!
看看做完,LED燈光閃爍的樣子吧!
這個WS2812B使用上真的是太容易了! 不過我的最終目標是把這燈條拿來做一把光劍。 只要把這個燈條加上我之前做過實驗的 DFplayer Mini MP3 模組, 這個算盤打的很如意!哈哈,看看我是不是做到吧!
完。







Grady, thank you very much!!
Hi John,
Thanks for your nice compliment!