In this tutorial, we will create a synchronized lighting system using the ESP32 and WS2812 LEDs that can be controlled remotely via MQTT. This system allows multiple users to change the color of the lights simultaneously, creating a connected experience regardless of location. The project utilizes the SunFounder ESP32 IoT kit, which includes a powerful microcontroller with Wi-Fi capabilities, making it ideal for IoT applications.
WS2812_strip.ON
Throughout the video, we will walk through the necessary setup, wiring, and code implementation to achieve this effect. If you need further clarification, be sure to check the video at specific timestamps (in video at mm:ss).
Hardware Explained
The primary components of this project include the ESP32 microcontroller, WS2812 LED strip, and an MQTT broker. The ESP32 is a versatile microcontroller with built-in Wi-Fi and Bluetooth capabilities, allowing it to connect to the Internet easily. It serves as the brain of our project, handling the communication and controlling the LED strip.
The WS2812 LED strip consists of individually addressable RGB LEDs, which can be controlled to display a wide range of colors. Each LED can be turned on or off and set to any color using a single data line, making it perfect for dynamic lighting effects. The MQTT broker facilitates the communication between different clients, allowing users to publish and subscribe to topics that control the LED colors.
Datasheet Details
Manufacturer
Adafruit
Part number
WS2812B
Logic/IO voltage
3.5 - 5.5 V
Supply voltage
5 V
Output current (per channel)
20 mA
Peak current (per channel)
60 mA
PWM frequency guidance
400 Hz
Input logic thresholds
0.2Vcc (low), 0.7Vcc (high)
Voltage drop / RDS(on) / saturation
0.5 V
Thermal limits
Operating temperature: -25 to 85 °C
Package
Individual 5050 SMD
Notes / variants
Available in various lengths and configurations
Ensure adequate power supply for the WS2812 strip to avoid voltage drops.
Use a common ground between the ESP32 and the LED strip.
Keep data lines short to prevent signal degradation.
Consider using a capacitor (1000μF) across the power supply to smooth out voltage spikes.
Use appropriate resistors on the data line to prevent signal reflection.
Be mindful of the total current draw of the LED strip; use external power when necessary.
Wiring Instructions
To wire the ESP32 with the WS2812 LED strip, start by connecting the power supply. Connect the red wire from the LED strip to a 5V power source and the black wire to the ground. Next, connect the data line (yellow wire) from the WS2812 strip to pin 14 on the ESP32. Ensure that the ESP32 is also connected to the same ground as the LED strip to maintain a common reference.
After setting up the power and data connections, connect the ESP32 to your computer using a micro USB cable for programming. You will need to ensure the ESP32 is powered on while programming to establish a connection. Once wired, you can proceed to upload the code and test the setup.
esp32-47-cheer-light-wiring
Code Examples & Walkthrough
The code begins by including necessary libraries for Wi-Fi and MQTT functionality. The identifiers ssid and password are used to store your Wi-Fi credentials, while mqtt_server holds the address of the MQTT broker.
Next, we define the supported CheerLights colors and their corresponding RGB values using arrays. This allows the program to easily access the color settings based on user input.
The main loop continuously checks the MQTT connection and processes incoming messages that control the LED colors. The callback() function is triggered when a message is received on the subscribed topic.
Demonstration / What to Expect
Once everything is set up and the code is uploaded, you should be able to change the color of the WS2812 LEDs by sending messages to the MQTT topic. If another user changes the color, all connected devices will reflect the change simultaneously. Be cautious of potential issues such as reversed polarity or improper connections, which could prevent the LEDs from functioning correctly (in video at mm:ss).
Video Timestamps
00:00 Start
2:00 Introduction
3:48 Documentation page
6:33 Wiring explained
7:35 Arduino Code explained
15:03 Selecting ESP32 board and COMP port in Arduino IDE
16:46 CheerLighs Demonstration
图像
WS2812_strip.ON
esp32-47-cheer-light-wiring
WS2812_strip.ON
esp32-47-cheer-light-wiring
848-ESP32 Tutorial 47/55- Arduino code for cheer light