Categories

WS2812B RGB Shield and ESP8266 example

We are going to look at a WS2812b led or neopixel in this example, again we use a Wemos mini and an RGB LED shield

Lets take a look a the shields and boards that are required

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
An RGB LED shield – sometimes known as Neopixel
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side

 

 

Parts List

1 x Wemos Mini
1 x Wemos Dual Base (optional)
1 x RGB shield

I connect the Wemos Mini to the dual base and then put the WS2812b shield along side this. You could stack these.

 

Code

This library is required – you can install these via the library manager

https://github.com/adafruit/Adafruit_NeoPixel

 

#include <Adafruit_NeoPixel.h>
#define NEOPIN D2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, NEOPIN, NEO_GRB + NEO_KHZ800);
char SerialInput;
void setup()
{
// initialize journal printer sensors to default states
Serial.begin(9600);
pixels.begin(); // This initializes the NeoPixel library.
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}
void loop()
{
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
SerialInput = Serial.read();
//verify incoming option
switch(SerialInput)
{
case '1':
// RED ON
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case '2':
// ALL off
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case '3':
// GREEN ON
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case '4':
// ALL off
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case '5':
// BLUE ON
pixels.setPixelColor(0, pixels.Color(0, 0, 255)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case '6':
// ALL off
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
break;
}
}

 

Output

Open the serial monitor and type in the number 1 to 6 to see a different colour on the LED

 

 

Links

 

Smart Electronics D1 mini – Mini NodeMcu 4M bytes development board based ESP8266 by WeMos

Dual Base Expansion board for WeMos D1 mini NodeMCU ESP8266

For WeMos D1 Mini RGB LED Shield Esp8266 For Wemos D1 Mini Shield Expansion Board For Arduino

Be Sociable, Share!

Comments are closed.