Smart RGB Lamp Controlled Via ESP NOW

by Northstrix in Circuits > Microcontrollers

3390 Views, 10 Favorites, 0 Comments

Smart RGB Lamp Controlled Via ESP NOW

IMG_20210605_192559.jpg

In this project I'm going to show you how to make a smart RBG lamp which can be easily controlled remotely using the ESP NOW protocol.

Supplies

Version without remote control:

1) ESP32 x1

2) 128x32 OLED display x1

3) 470 ohm resistor x1

4) 20k potentiometers x3

5) Buttons x2

6) WS2812 LEDs (as much as you need)

7) 5V power supply x1


Remotely controlled version:

1) ESP32 x1

2) ESP8266 x1

3) 128x32 OLED display x1

4) 470 ohm resistors x2

5) 20k potentiometers x2

6) Buttons x2

7) WS2812 LEDs (as much as you need)

8) 5V power supplies x2

Install the Drivers and Configure Arduino IDE *optional

If you've never flashed ESP32 or ESP8266 before you'll need to configure Arduino IDE and install drivers to upload the firmware to the boards, you can find drivers here:

CH340 driver for ESP8266: https://sparks.gogo.co.nz/ch340.html

CP210x driver for ESP32: https://www.silabs.com/developers/usb-to-uart-brid...

In case you don't have Arduino IDE, you can download it here: https://www.arduino.cc/en/software

Configuring IDE isn't a part of this tutorial, you can read about it here:

ESP32: https://randomnerdtutorials.com/installing-the-esp...

ESP8266: https://randomnerdtutorials.com/how-to-install-esp...

Build the Circuit

I've included both schematic and circuit diagrams to make it easier for you.

Schematic Diagram

Schematic diagram.jpg

Circuit Diagram

Circuit diagram.png

Download the Firmware

You can download the firmware here https://github.com/Northstrix/Smart-RGB-lamp-contr...

Adjust one of those variables if you need.

#define LED_PIN 13 // WS2812 data pin
#define LED_COUNT 4 // Number of LEDs
int br = 127; // Default brightness (0 - 0%; 127 - 50%; 255-100%)
int dd = 50; // Debounce delay for brightness buttons

I've used the Adafruit NeoPixel library to control the strip, you can find the official documentation for this library here: https://learn.adafruit.com/adafruit-neopixel-uberg...

Flash ESP32

IMG_20210529_141810.jpg

Upload the firmware that you've just downloaded to the ESP32.

Test the Device

It's time to test the intermediate result.

Rotate the potentiometers to adjust hue and saturation.

Press the buttons to change the brightness.

Hold two buttons simultaneously for half a second to change the mode.

Note: You can only change the brightness in the default mode and the lamp mode.

Default Mode

IMG_20210514_100118.jpg
IMG_20210514_095628.jpg
IMG_20210514_100423.jpg
IMG_20210514_100310.jpg

Nothing unusual, just fill the whole strip with the selected color.

  • Rotate the potentiometer attached to the D34 pin for rough hue adjustment.
  • Rotate the potentiometer attached to the D35 pin for precise hue adjustment.
  • Rotate the potentiometer attached to the D25 pin for saturation adjustment.
  • Press the button attached to D33 pin to the increase the brightness.
  • Press the button attached to D32 pin to the decrease the brightness.

Rainbow Mode

IMG_20210514_095809.jpg

Fills the whole strip with every color of the rainbow. Color changes automatically.

Slow Rainbow Mode

IMG_20210514_095838.jpg

The same as the rainbow mode, but takes about an hour to complete the cycle.

Lamp Mode

IMG_20210514_095902.jpg
IMG_20210514_095923.jpg

Turns the whole strip into a lamp with controllable brightness.

  • Press the button attached to the D33 pin to increase the brightness.
  • Press the button attached to the D32 pin to decrease the brightness.

Shinning Moon Mode

IMG_20210514_095930.jpg

Fills the whole strip with the fully saturated white color, and sets the peak brightness.

Be careful, using this mode for a long time can damage your strip.

Make a Lamp

IMG_20210606_224641_hdr.jpg
IMG_20210606_224616.jpg
IMG_20210606_224631_hdr.jpg

This step is entirely up to you. Choose any shape and size you like and don't forget to count the number of LEDs in your lamp. I took a CN Tower in Toronto as an inspiration for my lamp.

Moving Forward

It's time to get to the part when this device becomes remotely controlled.

By the way, if you don't need the wireless capability of this device you can stop here.

Get the MAC Address of the Receiver Board

mac.png

To get the MAC address of the board upload this code to the board.

#include <ESP8266WiFi.h>

void setup(){
  Serial.begin(115200);
  Serial.println();
  Serial.println(WiFi.macAddress());
}
 
void loop(){

}

Then open the serial monitor, and reboot the board.

If done correctly, you should see the MAC address in the console.

The MAC address of this board is 5C:CF:7F:FD:85:1D

Flash the Transmitter Board

IMG_20210529_141810.jpg

For some unknown reason, ESP32 stopped measuring the voltage on the D25 pin after I've included an ESP NOW library that's why there are two potentiometers instead of three, so I've decided to sacrifice the saturation adjustment feature. If you have a solution to this problem please post it down in the comment section.

You can find the firmware here https://github.com/Northstrix/Smart-RGB-lamp-contr...

Don't forget to adjust the number of LEDs attached to the transmitter, set the saturation, and replace the MAC address in the firmware with the MAC address of your receiver board.

#define LED_COUNT 4 // Number of LEDs
int sat = 255;
uint8_t broadcastAddress[] = {0x5C, 0xCF, 0x7F, 0xFD, 0x85, 0x1D};

Flash the Receiver Board

IMG_20210207_164031.jpg

You can get the firmware here https://github.com/Northstrix/Smart-RGB-lamp-contr...

Don't forget to adjust the number of LEDs and set the saturation.

#define LED_COUNT 60 // Number of LEDs
int sat = 255;

Connect the Lamp to the Receiver Board

FB9ON33KKTQ92EL.jpg

Connect the 470-ohm resistor between the D4 pin of the ESP8266 and the DI pin of the WS2812 LED strip.

Connect the GND pin of the ESP8266 to the GND pin of the WS2812 LED strip.

Connect the third pin of the ESP8266's power convertor to the +5V pin of the WS2812 LED strip.

And don't forget to connect the capacitors.

Test the Device

IMG_20210605_192412.jpg
IMG_20210605_192703.jpg
IMG_20210605_195631.jpg
IMG_20210605_192532.jpg
IMG_20210605_192712.jpg

Note that I removed two modes from the wireless version: rainbow and slow rainbow.

Conclusion

Although this project is raw and no more than an MVP I believe it can one day become a fully functional smart lamp controlled not just via ESP NOW protocol, but also via Alexa or Telegram. If you like this project and you can make it better, please write a couple of your effects, modes, or features for this lamp, post the code on GitHub, and leave the link to the code in the comment section. With your help, this lamp can become an open-source alternative to the products that are already on the market or even better.

Thank you so much for reading this tutorial.