How to Control WS2812B Individually Addressable LEDs Using Arduino
How to Control WS2812B Individually Addressable LEDs Using Arduino
FEATURED PROJECTS
report this ad
What’s great about these LEDs is that we can control even the
entire LED strip with just a single pin from our Arduino board.
Each LED has three connectors at each end, two for the
powering and one for the data. The arrow indicates the data flow
direction. The data output pad of the previous LED is connected
to the Data Input pad of the next LED. We can cut the strip to any
size we want, as well as distance the LEDs using some wires.
report this ad
As for the powering they work on 5V and each Red, Green and
Blue LED draws around 20mA, or that’s total of 60mA for each
LED at full brightness. Note that when the Arduino is powered
via the USB, the 5V pin can handle only around 400 mA, and
when powered using the barrel power connector, the 5V pin can
handle around 900 mA.
If you are using more LEDs and the amount of current that they
would draw exceeds the limits mentions above, you must use a
separate 5V power supply. In such a case you also need to
connect the two Ground lines two each other. Additionally it is
recommended to use a resistor of around 330 Ohms between
the Arduino and the LED strip data pin in order to reduce the
noise on that line, as well as a capacitor of around 100uF across
the 5V and Ground to smooth out the power supply.
You can get the components needed for this example from the
links below:
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 20
CRGB leds[NUM_LEDS];
void setup() {
void loop() {
Example 2
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 20
CRGB leds[NUM_LEDS];
void setup() {
void loop() {
Here the first “for” loop lights up all 20 LEDs in blue, from the
first to the last LED with 40 milliseconds delay. The next “for”
loop lights up again all 20 LEDs, but this time in red color and in
reverse order, from the last to the first LED.
You can check her website article where she explains the entire
process making the table, starting from cutting and assembling
the wooden construction, to soldering and connecting all
electronics parts together. Here I will explain how the electronics
part work, how to build the custom Android application and
program the Arduino board.
You can get the components needed for this example from the
links below:
Source Codes
Here’s the Arduino code for this project and if we exclude the
Bluetooth color control feature, we can notice that the code is
actually very simple.
#include "FastLED.h"
#define NUM_LEDS 45
#define LED_PIN 2
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
// Set the 45 proximity sensors pins as inputs, from digit
al pin 3 to pin 48
for (int pinNo = 0 + 3; pinNo <= 45 + 3; pinNo++) {
pinMode(pinNo, INPUT);
}
}
void loop() {
for (int pinNo = 0; pinNo <= NUM_LEDS-1; pinNo++) {
leds[pinNo] = CRGB( 0, 255, 0); // Set all 45 LEDs to
green color
// If an object is detected on top of the particular sen
sor, turn on the particular led
if ( digitalRead(pinNo + 3) == LOW ) {
leds[pinNo] = CRGB( 0, 0, 255); // Set the reactive LE
D to bluee
}
}
FastLED.show(); // Update the LEDs
delay(20);
}
In the main loop using a single “for” loop we set all LEDs to a
particular color, and also check whether the proximity sensor
has detect an object. If that’s true, or a LOW logic state in this
case, the particular reactive color will be set to the particular
LED. At the end using the FastLED.show() function we update
the LEDs colors.
You can download the Android app below, as well as the MIT
App Inventor project file:
DIY_Reactive_LED_Table_Control DOWNLOAD