Home » ESP32 and WS2812 RGB led ring example

ESP32 and WS2812 RGB led ring example

by shedboy71

This was a WS2812b led ring that I purchased for low cost. There are 12 LEDs in total on this and once you solder 3 cables to the module you are ready to go

We will create an example for the Lolin32 using the Arduino IDE

Connect Vcc to Wemos Lolin 3.3 volts, Gnd to Gnd and the In to 15, you can change this to any pin but you will need to change the code below

Here is a little layout so you get the idea

esp32 and led ring

esp32 and led ring

In the code example below we will display red, green and blue on all the LEDs

 

Code

You will need the Adafruit Neopixel library installed for this example

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN            15

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      12

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 250; // delay for half a second

void setup() 
{
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() 
{
  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(255,0,0)); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }

  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,255,0)); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }

  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,0,255)); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
}

[/cpp]

 

Link

Only $1.30 for this board, we'll worth a play about with

1pcs 12-bit WS2812 5050 RGB LED intelligent full-color RGB ring development board ring

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.