WiFi-Controlled WS2812 LED Lamp With ESP32-C3 and Blynk

by dziubym in Circuits > Arduino

165 Views, 1 Favorites, 0 Comments

WiFi-Controlled WS2812 LED Lamp With ESP32-C3 and Blynk

I Designed a Universal LED Controller… Then Everything Went Wrong

In this project, I will show you how to build a small RGB LED lamp using an ESP32-C3, an 8×8 WS2812 LED matrix, and Blynk.

The lamp can be controlled from a smartphone using a custom Blynk interface. You can turn the lamp on and off and select between several predefined colors. The Blynk interface also displays an image representing the current state and color of the lamp.

The project uses a custom LED controller PCB, but the same principle can be adapted to a breadboard or another ESP32-based setup.

The controller uses an 74AHCT125N level shifter to convert the ESP32-C3's 3.3V logic signal to the 5V logic level used by the WS2812 LEDs.

You can access the full video tutorial for this project using the link below



What you will build

The finished lamp will have:

  1. ESP32-C3 microcontroller
  2. 8×8 WS2812 RGB LED matrix
  3. 74AHCT125N logic-level shifter
  4. Blynk smartphone interface
  5. 5V power supply
  6. 3D-printed lamp enclosure

The lamp has five selectable colors:

  1. White
  2. Red
  3. Blue
  4. Green
  5. Pink

Supplies

esp32-c3-oled.png
AHCT.png
pcb.png

You will need the following components:

  1. ESP32-C3 development board
  2. 8×8 WS2812 LED matrix
  3. 74AHCT125N logic level shifter
  4. Custom LED controller PCB or a breadboard
  5. 5V DC power supply
  6. DC power socket
  7. Dupont wires
  8. M3 screws
  9. Double-sided tape
  10. 3D-printed lamp enclosure

The controller PCB provides a dedicated connector for the WS2812 matrix and contains the level-shifting circuitry required to interface the ESP32-C3 with the LEDs.

How the LED Controller Works

The ESP32-C3 operates using 3.3V logic, while the WS2812 LEDs are powered from 5V.

The 74AHCT125N is used as a logic-level buffer. It converts the 3.3V signal from the ESP32-C3 into a 5V signal suitable for the WS2812 data input.

The basic signal path is:

ESP32-C3 → 74AHCT125N → WS2812 LED matrix

The LED matrix is powered from the 5V supply.

For this project, the controller is used only to control the WS2812 LEDs. The other functionality available on the controller is not required.

Connect the LED Matrix

IOT_lamp_diag.png

For this project, I used my custom LED controller PCB, which I designed for use in several different LED projects. It contains some additional components and functionality that are not required for this particular lamp.

You don't need to build the same PCB. You can create your own PCB or build the circuit on a breadboard using just the components required for this project. The wiring below shows the relevant connections

  1. ESP32-C3 GPIO3 → 74AHCT125N 1A
  2. 74AHCT125N 1Y → series resistor → WS2812 DIN
  3. 74AHCT125N 1OE → GND to enable the channel
  4. 5V → ESP32-C3, 74AHCT125N VCC and WS2812 +5V
  5. All GND connections must be common

The 74AHCT125N converts the ESP32-C3's 3.3V data signal to a 5V logic signal suitable for the WS2812 LEDs.

A 1000 µF electrolytic capacitor is connected across the 5V and GND rails near the LED strip to help handle current fluctuations when the LEDs change brightness.

Make sure the data signal is connected to the DIN/input end of the WS2812 strip.

Signal path:

ESP32-C3 GPIO3 → 74AHCT125N → resistor → WS2812 DIN


A simpler option

If you want to simplify the circuit, you can omit the 74AHCT125N level shifter and connect the WS2812 data input directly to a 3.3V GPIO pin of the ESP32-C3, for example GPIO3.

In that case, simply power both the ESP32-C3 and the LED strip from the 5V power supply, connect their grounds together, and connect GPIO3 directly to the DIN pin of the LED strip.

This will most likely work, and many WS2812 installations are operated this way. However, I decided to use the level shifter because the WS2812 is specified for a 5V logic-level data signal when powered from 5V. I wanted to follow the recommended approach rather than relying on the fact that a 3.3V signal often works in practice.

So, the level shifter isn't necessarily required for this project, but it provides a more robust and technically correct interface between the ESP32-C3 and the WS2812 LEDs.

Install the Arduino Libraries

The project is programmed using the Arduino IDE.

Install the following libraries through the Arduino Library Manager:

Adafruit NeoPixel

The project uses the Adafruit NeoPixel library to control the WS2812 LEDs.

I originally considered using FastLED, but I experienced timing compatibility problems with my ESP32 setup. Adafruit NeoPixel provided reliable communication with the LEDs.

link: https://github.com/adafruit/adafruit_neopixel

Blynk

Install the Blynk library to allow the ESP32-C3 to communicate with Blynk Cloud.

link: https://github.com/Blynk-Technologies/blynk-library


You will also need the appropriate ESP32 board support installed in Arduino IDE.


Install ESP32 Board Support in Arduino IDE

ESPInstall.png

Install ESP32 Board Support in ArduIf you are using an ESP32 with Arduino IDE for the first time, you need to install the ESP32 board package first.

  1. Open Arduino IDE and go to File → Preferences.
  2. In Additional Boards Manager URLs, add the following URL:
  3. https://espressif.github.io/arduino-esp32/package_esp32_index.json
  4. Click OK.
  5. Go to Tools → Board → Boards Manager.
  6. Search for ESP32 and install esp32 by Espressif Systems.
  7. After installation, select your ESP32-C3 board under Tools → Board → ESP32 Arduino.


Create the Blynk Device

dev1.png
dev2.png
dev3.png
V2.png
V1.png
V3.png

Step 5: Create the Blynk Device

Open Blynk Cloud (https://blynk.cloud)and create a new device.

If you are not familiar with BLYNK please check this instructable of mine

https://www.instructables.com/IoT-Made-Easy-ESP8266-Blynk-App-to-Control-LED-Rem

For this project, I called my device Cube.

After creating the device, obtain the Blynk credentials that will be used in the Arduino code.

#define BLYNK_TEMPLATE_ID "TMPL4dnYZPU1C"
#define BLYNK_TEMPLATE_NAME "CUBE"
#define BLYNK_AUTH_TOKEN "m0VoHhk55wyP74vJtqYyFVEzyW9C0iAs"


You will also need to create three data sources.

Create the following:

Data source Virtual Pin Purpose

Off Switch V2 Turns the lamp on/off

Fixed Color V1 Selects the lamp color

Lamp Color V3 Updates the image shown in the app (different lamp colors)

Create the Blynk Mobile Dashboard

IMG_6588.png

Open the Blynk mobile app and connect to your device.

Initially, the dashboard will be empty.

We will add three widgets.

On/Off Switch


Add a Switch widget and connect it to the Off Switch data source.

This data source uses virtual pin V2.

The switch has two possible values:

  1. 0 = lamp off
  2. 1 = lamp on

When the switch is turned on, the lamp will initially use white light.


Segmented switch


Add a Segmented Switch widget and connect it to the Fixed Color data source.

This data source uses virtual pin V1.

The six possible values are:

Value Function

0 White

1 Red

2 Blue

3 Green

4 Pink

5 Off

The first five values select colors.

Value 5 is reserved for the lamp's off state.

The segmented switch is only displayed when the lamp is switched on.


Image Gallery


The final widget is an Image Gallery.

Instead of sending commands to the lamp, this widget receives information from it.

Provide URLs to images showing the lamp in the following states:

  1. Off
  2. White
  3. Red
  4. Blue
  5. Green
  6. Pink

The images can be hosted on any online image-hosting service of your choice

Each image has an index corresponding to the color value.

Connect the Image Gallery to the Lamp Color data source on V3.

This allows the application to display an image corresponding to the current lamp state.

For example:

  1. V3 = 0 → white lamp image
  2. V3 = 1 → red lamp image
  3. V3 = 2 → blue lamp image
  4. V3 = 3 → green lamp image
  5. V3 = 4 → pink lamp image
  6. V3 = 5 → lamp-off image


How the Blynk Interface Works

The control system is quite simple.

When you select a color in the Blynk app, its value is sent to the ESP32-C3 through V1.

The Arduino code receives the value and uses it to select the corresponding RGB color.

The LEDs are then updated.

The same value is sent back to Blynk through V3.

The Image Gallery receives this value and displays the corresponding image.

This means the image in the app always reflects the current lamp color.

When the on/off switch is turned off, the ESP32-C3:

  1. Turns the LEDs off.
  2. Sends value 5 to V3.
  3. The Image Gallery changes to the off-state image.
  4. The color selector is hidden.

When the lamp is turned back on, the previously selected color is restored.

Arduino Code

The complete Arduino sketch controls the WS2812 matrix and communicates with Blynk.

The LED strip is created using the Adafruit NeoPixel library.

The important parameters are the LED data pin and the number of LEDs.

For an 8×8 matrix, the number of LEDs is:

8 × 8 = 64 LEDs

The program also contains a table of the available colors and variables that store:

  1. whether the lamp is on or off
  2. the currently selected color

A helper function receives a color index, finds the corresponding RGB value, and applies that color to all 64 LEDs.

The Blynk handlers then take care of the user interface:

V2 – On/Off

When V2 changes:

  1. 0 turns the LEDs off.
  2. 1 turns the lamp on using the currently selected color.
  3. V3 is updated so the correct image is shown.
  4. The color selector is hidden or displayed as appropriate.

V1 – Color

When V1 changes:

  1. The selected color index is stored.
  2. If the lamp is on, the LED matrix is updated.
  3. The same color index is sent to V3.

V3 – Image Gallery

V3 is used by the ESP32-C3 to tell the Blynk app which image should be displayed.

You can download the complete source code from the project resources.

Downloads

3D-Printed Lamp Enclosure

L2.png
L1.png
L5.png
L4.png
L3.png
L6.png

For the enclosure, I made several changes to the original design.

The lamp shade was reprinted to make it more solid.

I also modified the base to include:

  1. Mounting points for the LED controller
  2. M3 screw holes
  3. An opening for the DC power socket
  4. Space for the electronics

A bottom cover was also printed to hide the controller and electronics once the lamp was assembled.

Lamp Is Ready:)

pink.png
blue.png

You’ve now built a fully functional cloud-connected LED controled Lamp using the ESP32-C3 and Blynk .

Stay tuned for future projects—and happy tinkering!

Enjoyed this project? Consider buying me a coffee on Ko-fi!