WS2812 Tutorial
WS2812 and Arduino UNO Connection
Connection:
- PWR+5V to Arduino 5V
- GND to Arduino GND
- Data Input (DI) to Arduino Digital Pin A6
An Arduino UNO microcontroller board is shown connected to a circular WS2812 addressable LED strip. The Arduino's 5V pin is connected to the strip's power input, its GND pin to the strip's ground, and its digital pin A6 to the strip's data input (DI).
Download the necessary library from: https://github.com/adafruit/Adafruit_NeoPixel
You can open the standard test code within the Arduino IDE after installing the library.
Example Code
Please pay attention to the LED count in your strip. If your strip has 24 LEDs, you need to change the number '60' in the code to '24'.
#include <Adafruit_NeoPixel.h>
#define PIN 6
// 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/WS28
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WSZ
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixe
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pix
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NE
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capaci
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's
// and minimize distance between Arduino and first pixel.
// on a live circuit...if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Some example procedures showing how to display to the pixels
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
}