8.5 CheerLights¶
CheerLights is a global network of synchronized lights that can be controlled by anyone.
Join the @CheerLights LED color-changing community, which allows LEDs around the world to change colors simultaneously.
You can place your LEDs in a corner of your office to remind yourself that you are not alone.
In this case, we also utilize MQTT, but instead of publishing our own messages, we subscribe to the “cheerlights” topic. This allows us to receive messages sent by others to the “cheerlights” topic and use that information to change the color of our LED strip accordingly.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
---|---|---|
ESP32 Starter Kit |
320+ |
You can also buy them separately from the links below.
COMPONENT INTRODUCTION |
PURCHASE LINK |
---|---|
- |
|
How to do?
Build the circuit.
Then, connect ESP32-WROOM-32E to the computer using the USB cable.
Open the code.
Open the
iot_5_cheerlights.ino
file located in theesp32-starter-kit-main\c\codes\iot_5_cheerlights
directory, or copy the code into the Arduino IDE.After selecting the board (ESP32 Dev Module) and the appropriate port, click the Upload button.
The
PubSubClient
andAdafruit_NeoPixel
libraries are used here, you can install them from the Library Manager.
Locate the following lines and modify them with your
<SSID>
and<PASSWORD>
.// Replace the next variables with your SSID/Password combination const char* ssid = "<SSID>"; const char* password = "<PASSWORD>";
Find the next line and modify your
unique_identifier
. Guarantee that yourunique_identifier
is truly unique as any IDs that are identical trying to log in to the same MQTT Broker may result in a login failure.// Add your MQTT Broker address: const char* mqtt_server = "mqtt.cheerlights.com"; const char* unique_identifier = "sunfounder-client-sdgvsasdda";
After selecting the correct board (ESP32 Dev Module) and port, click the Upload button.
At this point, you can see that your RGB strip is displaying a certain color. Place it on your desk and you will notice that it periodically changes colors. This is because other @CheerLights followers are changing the color of your lights!
Open the Serial Monitor. You will see messages similar to the following:
WiFi connected
IP address:
192.168.18.77
Attempting MQTT connection...connected
Message arrived on topic: cheerlights.
Message: oldlace
Changing color to oldlace
Control global @CheerLights devices
Join the Discord Server and utilize the CheerLights bot to set the color. Simply type
/cheerlights
in any of the channels on the CheerLights Discord Server to activate the bot.Follow the instructions provided by the bot to set the color. This will allow you to control CheerLights devices globally.