TIn this project, I’ll show you how you can build your own mood light. You’ll use an ESP8266 to remotely control the color of your light using your smartphone or any other device that has a browser. This project is called $10 DIY WiFi RGB LED Mood Light.
To learn more about the ESP8266 and RGB LEDs use the following tutorials as a reference:
- How do RGB LEDs work?
- ESP8266 RGB Color Picker
- Getting started with the ESP8266
- ESP8266 web server with NodeMCU
- Flashing NodeMCU firmware
- ESP8266 troubleshooting guide
Parts List
Here’s the hardware that you need to complete this project:
- 1x ESP8266-12E – read Best ESP8266 Wi-Fi Development Boards
- 1x RGB LED Strip

- 1x 12V Power Supply
- Device to reduce voltage from 12V to 5V
- Alternative – LM7805 with heat sink
- Recommended – Step down buck converter module

- 3x NPN Transistors 2N2222 or equivalent
- 3x 1k Ohm Resistors
- 1x Breadboard
- Jumper wires
- Table Lamp with Mood Light Look

Flashing Your ESP with NodeMCU
In this tutorial we are going to use the NodeMCU firmware. You have to flash your ESP with NodeMCU firmare.
Downloading ESPlorer IDE
I recommend using the ESPlorer IDE which is a program created by 4refr0nt to send commands to your ESP8266.
Follow these instructions to download and install ESPlorer IDE:
- Click here to download ESPlorer
- Unzip that folder
- Go to the main folder
- Run “ESPlorer.jar” file
- Open the ESPlorer IDE

Uploading Code
You should see a window similar to the preceding Figure, follow these instructions to upload a Lua file:
- Connect your ESP8266-12E that has built-in programmer to your computer
- Select your ESP8266-12E port
- Press Open/Close
- Select NodeMCU+MicroPtyhon tab
- Create a new file called init.lua
- Press Save to ESP
Everything that you need to worry about or change is highlighted in red box.

Code
Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua“.
Don’t forget to add your network name (SSID) and password to the script below.
IMPORTANT: the embedded script below was made in 2016 and it works with an older version of the Lua firmware. If you’re running a newer version of the Lua firmware, you’ll need to use this script instead: ESP8266_RGB_Color_Picker_New.lua.
<pre class="wp-block-syntaxhighlighter-code">-- Gnd_To_Vcc
--
wifi.setmode(wifi.STATION)
wifi.sta.config("REPLACE_WITH_YOUR_SSID","REPLACE_WITH_YOUR_PASSWORD")
print(wifi.sta.getip())
function led(r, g, b)
pwm.setduty(5, r)
pwm.setduty(6, g)
pwm.setduty(7, b)
end
pwm.setup(5, 1000, 1023)
pwm.setup(6, 1000, 1023)
pwm.setup(7, 1000, 1023)
pwm.start(5)
pwm.start(6)
pwm.start(7)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
buf = buf.."HTTP/1.1 200 OK\n\n"
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<!DOCTYPE html><html><head>";
buf = buf.."<meta charset=\"utf-8\">";
buf = buf.."<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">";
buf = buf.."<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
buf = buf.."<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\">";
buf = buf.."<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js</a>";
buf = buf.."<a href="https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js">https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js</a>";
buf = buf.."</head><body><div class=\"container\"><div class=\"row\"><h1>ESP Color Picker</h1>";
buf = buf.."<a type=\"submit\" id=\"change_color\" type=\"button\" class=\"btn btn-primary\">Change Color</a> ";
buf = buf.."<input class=\"jscolor {onFineChange:'update(this)'}\" id=\"rgb\"></div></div>";
buf = buf.."<script>function update(picker) {document.getElementById('rgb').innerHTML = Math.round(picker.rgb[0]) + ', ' + Math.round(picker.rgb[1]) + ', ' + Math.round(picker.rgb[2]);";
buf = buf.."document.getElementById(\"change_color\").href=\"?r=\" + Math.round(picker.rgb[0]*4.0117) + \"&g=\" + Math.round(picker.rgb[1]*4.0117) + \"&b=\" + Math.round(picker.rgb[2]*4.0117);}</script></body></html>";
if(_GET.r or _GET.g or _GET.b) then
led(_GET.r, _GET.g,_GET.b)
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
</pre>
Schematics
Now follow these schematics to create the final circuit.
Your ESP IP Address
When your ESP8266 restarts, it prints in your serial monitor the ESP IP address. Save that IP address, because you’ll need it later.
In my case, the ESP IP address is 192.168.1.105. If you experience problems seeing your IP read this troubleshooting guide.
You’re all set!
Opening Your Web Server
Go to any browser and enter the IP address of your ESP8266. This is what you should see:

Click the input field and a small window opens with a color picker. Simply drag your mouse or finger and select the color for your RGB LED strip:

Finally, press the “Change Color” button:

Now, your mood light can be placed in your living room:

Go to the top of this page to see a video demonstration of this project.
Wrapping Up
This project shows a real world application for the ESP8266 board. If you don’t have an RGB LED strip, but you still want to try this project you can read this blog post ESP8266 RGB Color Picker that changes the color of an RGB LED with an ESP8266.
Do you have any questions? Leave a comment down below!
Thanks for reading.
4 thoughts on “$10 DIY WiFi RGB LED Mood Light with ESP8266 (Step by Step)”