For years I wanted to craft a plug and play RGB bulb with full control of every single LED of the set. Just a bulb that could be screwed like a regular one, set the wifi network up, and that’s it!
With this approach, there is no need to use a HUB.
The lamp/bulb is connected directly to the router.
But wait! You could buy something like that for a few bucks.
Yeah, but I didn’t want to be tied to any API, app or remote control.
My intention was not to create a standard of DIY lights. There are lots of options to buy or build better than this.
My idea was to control the whole process and use the LEDs as I please.
1. Where to start
- A broken LED bulb (0US$).
- A board with an ESP8266 chip (~5US$).
I used the Wemos D1 mini because it is widely used.
- A tiny 5v adapter (~2US$).
The one I’ve used is not an iPhone adapter. It’s a cheaper replica but it does its job pretty well.
- NeoPixel LED Ring, 16 x 5050 Ws2812 (~3US$).
- A few thin wires (0US$).
- A broken micro-USB connector (optional).
2. Connect and test the ring
First, solder the ring and the Wemos like this:
- Install Arduino IDE (https://www.arduino.cc/en/Main/Software).
2. Test the ring with this example made by Shae Erisson with some minor modifications:
Necessary library: https://github.com/adafruit/Adafruit_NeoPixel
3. Choose the board: LOLIN(WEMOS) D1 R2 & mini.
4. Select the USB port:
5. Burn the example:
Finally, It should look like this:
But it feels like:
3. Let’s burn the final code
You have 2 options =>
- Download the project code:
- Open the lamp_begins file and change the SSID with your wifi network name and its password.
Then choose the local IP. If you don’t know how the local IP should be, the easiest way to get it for any OS is visiting this site: https://www.whatismybrowser.com/detect/what-is-my-local-ip-address.
In my case, the local IP of my laptop is 192.168.0.3, so I’ve chosen 192.168.0.200 for the lamp.
Please, check twice the first 3 numbers of the IP and the gateway.
Otherwise it won’t work.
Now, burn it in the same way you did with the project file you have changed.
3.2. Step by step.
Please read the comments of each code file.
4. HTTP request. Let’s set some colors.
It’s very simple.
Just call the local IP slash the HEX colors separated with hyphens. That’s it. With this code example, you can set 2^n colors up to 16: 1,2,4,8,16.
4.1. Back to the board. Let’s make it red (#ff0000).
Go to your browser and GET:
It should look like this:
Instead of using your browser, you can use the Postman app.
4.2. Let’s set 2 colors(#ff0000 and #00ffa2). GET:
It should look like this:
4.16. Let’s make a rainbow.
5. Let’s connect everything (complete wiring)
I left the micro USB port of the Wemos free in order to update the board and fix potential bugs.
If you want, you can solder both cables (VCC and GND) to the Wemos board, but that could be impractical.
You can use other digital pinout. D6 isn’t mandatory.
Keep in mind that it is important to leave about 20cm (8") of cable between the 5v adapter and the tip of the cable in order to make the installation easier.
5.1. Detach the 5v adapter and solder the cables
6. Assemble everything
7. Use examples
If you are an iOS user, you might use the Shortcuts application. It’s really useful to create routines. Let’s create one using the bulb.
7.2. Watch OS app
I’ve built this app for my apple watch in order to handle the lights from it.
You can change the quantity of colors in the picker using the crown.
Every colors triggers a GET call like GET http://192.168.x.x/hex_color_here
7.3. Notifications instead of triggering manually
I’ve crafted a Drip Irrigation System for my wife’s plants. As you can see in the picture below, there is a tank full of water with 3 pumps inside it, one per each group. Those pumps provide the plants with water. At the top of the tank, there is an ultrasonic sensor connected to a Wemos which triggers notifications when the water level is too low or too high.
7.4. Etc.. Do whatever you want
There are 256³ (16 million) possible colors using #RRGGBB notation using only one value. If you use more than one color at the same time, the number goes too high. I think it would be (256³)¹⁶=256⁴⁰⁹⁶ possible combinations.
So, enjoy playing with it.
In the second part, I’ll make the network changing easier without needing to burn the code again, and I’ll add more features.
Bonus Track: data backup
I forgot to mention that using the lamp_with_data_backup code, every time you set a combination of colors, those values will be saved in the memory of the board. So, if the power goes down or you unplug the power cable, the lamp will reconnect itself to the network and it will set the saved combination of colors.
Suggestions are more than welcome!
Made with ❤