Help Center
< All Topics
Print

Interfacing the NoESP8266 Addressable WS2812 Neopixel Rings

Introduction

In this project, the addressable WS2812B LED ringmodule will be interfaced with the ESP8266 NodeMCU V2 using the Arduino IDE to program. The ESP8266 can be programmed to make the LED lights of the LED ring illuminate in various patterns and sequences.

Materials:

  • PC with Arduino IDE (2.3.2) installed
  • ESP8266 NODEMCU V2 Microcontroller
  • ESP8266 NODEMCU V2 Expansion Shield
  • Addressable WS2812 5050 RGB Neopixel Rings – 1-16 Bit
  • Wires and cables (To solder to the WS2812B modules and connect to the NodeMCU Shield)
  • USB-A to micro-USB cable (For Programming)

About the ESP8266 microcontroller

The ESP8266 NodeMCU V2 is a powerful microcontroller for IoT and wireless applications. Built on the reliable ESP12E module, it features 17 versatile GPIO pins supporting I2C, UART, PWM, and more. With an onboard CP2102 USB driver chip, it ensures stable USB communication, making it ideal for prototyping and advanced projects.

Click to Expand

About the Addressable WS2812 5050 RGB Neopixel Rings

WS2812 5050 RGB NeoPixel Rings combine vibrant RGB LEDs with integrated drivers in a compact design. Each LED is addressable, enabling individual control of colour and brightness for stunning lighting effects. With millions of colour combinations available, these rings are perfect for creative projects, from wearables to custom displays and interactive designs. These are available from 1 bit to as high as 32, with the ‘bit’ being the number of less. For example, 1 bit = 1 LED, 16 bit  = 16 LEDs.

In this tutorial we are using the 16 bit module.  Note: The WS2812B modules come unsoldered and will require to be soldered.

Click to Expand

The LED Ring Modules can be daisy-chained to expand the modules as shown below. Simply link the power, Data In (DI) and Data Out (DO) pins from one LED module to another. 

Click to Expand
Power Connection Pins:

Wire the 5V pin to the ESP8266’s Vin pin. Connect the GND pin to an available GND pin on the ESP8266.

Communication Pins:

Wire the DI (Data In) pin of the LED ring to pin D6. You don’t have to wire the DO (Data Out) pin to the ESP8266. The DO pins are used to activate another set of led modules via signal output.

The image below shows the wiring diagram for the ESP8266 and the WCMCU-2812B-16 LED ring.

Click to Expand

It is highly recommended to use the NodeMCU V2 Shield for ease of wiring. Simply wire the LED ring wires into the screw terminal points

Click to Expand

Libraries and Setup

The library needed to operate the LED ring is the Adafruit NeoPixel library by Adafruit. This can be downloaded here

Install the library and then copy and paste the code in the Code section below in the new IDE tab of the Arduino IDE.

Board Selection

There is a list of many ESP8266-based microcontrollers supported in the Arduino IDE. Select Generic ESP8266 as shown below. 

Click to Expand

Code

Note: As we are using a 16 bit microcontroller module the #define LED_COUNT line  (line #10) specifies the LED COUNT to be 16. If you are using a module that has 12 LEDs change the line to #define LED_COUNT 16.16  ff

/*
# AUTHOR: Nisheli P For MakerBotics
# VERSION: 1
# PURPOSE: Flashing individual LEDs in a neopixel ring
# License details: Attribution-ShareAlike 4.0 International CC BY-SA 4.0 Deed
*/

#include <Adafruit_NeoPixel.h>
#define LED_PIN 15 //This Pin is D8 on the ESP8266
#define LED_COUNT 16 //Number of LEDS on the Module. Modify to suit your module.
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic ‘v1’ (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
// setup() function — runs once at startup ——————————–
void setup() {
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}
// loop() function — runs repeatedly as long as board is on —————
void loop() {
  rainbow(10);             // Flowing rainbow cycle along the whole strip
}
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it’s OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we’ll make 5*65536/256 = 1280 passes through this loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    // strip.rainbow() can take a single argument (first pixel hue) or
    // optionally a few extras: number of rainbow repetitions (default 1),
    // saturation and value (brightness) (both 0-255, similar to the
    // ColorHSV() function, default 255), and a true/false flag for whether
    // to apply gamma correction to provide ‘truer’ colors (default true).
    strip.rainbow(firstPixelHue);
    // Above line is equivalent to:
    // strip.rainbow(firstPixelHue, 1, 255, 255, true);
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}

End Result

After successfully wiring the setup and running the code on the Arduino IDE, the LED ring should light up like the one below. The LEDs will change colour in a circular pattern and cycle through each LED.

Click to exapand

Downloadable Content

Please find this tutorial’s code on our GitHub page.

Credits

Table of Contents