WS2812B 8×8 LED Matrix Panel Review and Code
This post talks about how you can use the WS2812B 8×8 LED Matrix Panel with an Arduino.
WS2812B 8×8 LED Matrix Panel
The WS2812B 8×8 LED Matrix Panel is an square arrangement of 64 RGB LED’s. Each LED has its own LED driver which allows you to individually address and control each LED.
There are six pin holes where you can solder pin headers or wires to. These are the two sets for 5V and GND, a Digital In, and a Digital Out. This uses the standard WS2812B protocol to control the LED’s which only need a single data pin, 5V, and GND.
These can also be chained together to control multiple in parallel however you need to ensure that the current requirements will be met by your microcontroller.
This LED square can be used with the FastLED Arduino Library which allows you to easily control them. The LED’s are indexed numerically from the first LED (closest to the Data in port) to the last LED which is closest to the data out port.
Wiring it up to an Arduino
To wire up the WS2812B 8×8 LED Matrix Panel to an Arduino I am going to solder a 3 pin header onto the 5V, Data in, and GND pins. This will let me connect it to a breadboard and then connect it to the Arduino.
The 5V pin and GND pins are connected to the respective pins on the Arduino. The Data In (DIN) pin should ideally be connected to a resistor (of around 330 ohm) which is then connected to one of the digital pins on the Arduino. This resistor helps to reduce noise on the line and the LED panel may work without this. Here I will wire up the digital in pin to the Arduino’s digital pin three (with the noted resistor between it).
Programming the Arduino with the WS2812B 8×8 LED Matrix Panel
To program the WS2812B 8×8 LED Matrix Panel I am going to use the FastLED Arduino Library. This handles the complexity of the communication protocol and allows you to easily set the state of each LED.
This library can be added to the Arduino IDE by adding the “FastLED” library in the “Manage library” section of the Arduino IDE. Once this is added we can start using the libraries features.
To start with you need to include the libraries you want to use and set up the LED’s.
#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 64
CRGB leds[NUM_LEDS];
Here the pin to control it from the Arduino is defined (pin 3), the number of LED’s we have in our chain (64 = 8 * 8), and we then create the CRGB LED array to control the LED’s.
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}
The setup function just adds all the LED’s to the FastLED library so it is aware of them and can be used to control them.
void loop() {
for(int hue = 0; hue < 255; hue += 1) {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue, 128, 255);
}
FastLED.show();
delay(10);
}
}
Finally in the loop we loop the hue from 0 to 255 and set every LED to the same colour. This delays 10 milliseconds and then continues the hue loop.
This will slowly change the LED’s through a range of colours to give a pretty effect and test the LED’s.
Final Review
This WS2812B 8×8 LED Matrix Panel is a relatively cheap panel which allows you to easily program each of its LED’s. Since it works with the standard FastLED Arduino library it makes it quick to configure and write your sketch.
The LED’s are quite bright too which is very nice however you may want to dim them using the value attribute or by placing something in front of them to defuse them.
Overall this is a nice small package and I would recommend buying it for any LED needs!
Thanks! I followed along the tutorial, and not much time later, have the LEDs shining in front of me, big help for someone never done this before.