Fantastic RGB LEDs, and where to find them

This is a short post based on a small and simple lesson that introduces some of my students to a rather fancy “hello world” – controlling Neopixel-style* LED strings.

The proper technical name is WS2812b, and apart from “Neopixel”, “WS2812b” is the best search term to use when looking for info, example projects, and to purchase parts.

*notice my use of the expression “style”. What I mean to say is “cloned” in China. Real Neopixels are made by Adafruit, a very cool company who are the leading innovators in both technology and education content.

So, what do we need to get started?

  • Arduino Uno
  • 1x 330R resistor
  • Some DuPont jumper wires
  • 1x 100uF electrolytic capacitor
  • USB micro breakout
  • Soldering Iron
  • And, explained below, some WS2812B LEDs!

A Fancy Hello World with Neopixels

The simplest start is a Neopixel Stick – these 8-pixel RGB LED modules can be had for half a dollar off someplace like Aliexpress.

Unfortunately, they usually don’t come with connections attached, so you will also need to take up soldering as a hobby.

Once you’ve got connections, you then can connect as shown in the diagram below, with: (Module side >> Arduino Side)

  • GND >> GND
  • DIN >> D3
  • 4-7 VDC >> 5V

The following code will then be used to run and control the LEDs. Its assumed you already installed the Adafruit library…

#include <Adafruit_NeoPixel.h>
#define PIN 3
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
}

void loop() {
  pixels.clear();

  pixels.setPixelColor(0, pixels.Color(10,0,10));
  pixels.show();
  delay(100); 

  pixels.setPixelColor(1, pixels.Color(10,0,10));
  pixels.show();   
  delay(100); 

  pixels.setPixelColor(6, pixels.Color(10,0,10));
  pixels.show();  
  delay(100); 

  pixels.setPixelColor(7, pixels.Color(10,0,10));
  pixels.show();  
  delay(100); 

  delay(2000);
}

As can be seen if you run this, only four LEDs will light up. To get something a bit different, change the values of the RGB variable: pixels.Color(10,0,10). Its currently pink, but if you change the values, you can mix up any colour you want!

But what colours can it actually mix up? The following code will make a scrolling rainbow effect for you to enjoy.

#include <Adafruit_NeoPixel.h>
#define PIN 3
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
}

void loop() {
  pixels.clear();

  for (int i = 0; i < NUMPIXELS; i++)
  {
    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0, 150, 0));
    //update the hardware
    pixels.show();   // Send the updated pixel colors to the hardware.
    delay(500); // Pause before next pass through loop
  }
}

Paul Hoets is a freelance maker who lives in South Korea. If you liked this article and would like to contribute to his empire of dirt, silicon and tech. education, buy him a coffee!