$10 DIY WiFi RGB LED Mood Light with ESP8266 (Step by Step)

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.

First, watch the step by step video tutorial below

To learn more about the ESP8266 and RGB LEDs use the following tutorials as a reference:

If you like the ESP and you want to do more projects you can download my eBook Home Automation using ESP8266 here.

Let’s get started!

Parts List

Here’s the hardware that you need to complete this project:

rgb led strip

buck converter

white lamp

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

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:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the main folder
  4. Run “ESPlorer.jar” file
  5. Open the ESPlorer IDE

Uploading Code

You should see a window similar to the preceding Figure, follow these instructions to upload a Lua file:

  1. Connect your ESP8266-12E that has built-in programmer to your computer
  2. Select your ESP8266-12E port
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Create a new file called init.lua
  6. Press Save to ESP

Everything that you need to worry about or change is highlighted in red box.


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.

-- Rui Santos
-- Complete project details at https://randomnerdtutorials.com



function led(r, g, b)
    pwm.setduty(5, r)
    pwm.setduty(6, g)
    pwm.setduty(7, b)
pwm.setup(5, 1000, 1023)
pwm.setup(6, 1000, 1023)
pwm.setup(7, 1000, 1023)

    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");
        local _GET = {}
        if (vars ~= nil)then
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                _GET[k] = v
        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.."<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\"></script>";
        buf = buf.."<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js\"></script>";
        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)

View raw code


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 If you experience problems seeing your IP read this troubleshooting guide.

You’re all set!

ESPlorer IDE - fixed

Opening Your Web Server

Go to any browser and enter the IP address of your ESP8266. This is what you should see:

RGB color picker main selecting color

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:

selecting color

Finally, press the “Change Color” button:


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

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. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…

Enjoyed this project? Stay updated by subscribing our newsletter!

37 thoughts on “$10 DIY WiFi RGB LED Mood Light with ESP8266 (Step by Step)”

  1. Nifty little project! Now, and off the wall question: could this project be converted to use Bluetooth instead of wi-fi? Thanks!

  2. Hello Rui,

    Thank you very much for your great tutorials. I would like to ask you if I could use three MOSFETs instead of BJTs. I would also to ask you about a general “problem” I have. When I reset Esp-01, for example in the case of one led connected at GPIO-02 , blue led remains on and I have to remove this led at GPIO-02 and reset it again to work.

    Thank you in advance


    • Rui does look good after his followers, true. If you want to reach out to the global NodeMCU community rather then depending on Rui’s personal feedback I suggest you take a look at nodemcu.readthedocs.io/en/latest/en/support.

  3. Nice one 🙂

    Please don’t teach your readers bad practice, though!


    Is a no-go for two reasons:
    – tmr.delay() is bad practice and should only be used as a last resort. Also, IIRC the delay must not be more than 50µs. See http://nodemcu.readthedocs.io/en/latest/en/modules/tmr/#tmrdelay for details.
    – wifi.sta.config() is asynchronous and you need to wait until you get an IP address before you can continue, it may very well be more than 5000µs. See http://nodemcu.readthedocs.io/en/latest/en/upload/#initlua for a much better boot sequence.

      • That ain’t good enough, sorry.
        Without the delay wifi.sta.getip() will print nil because wifi.sta.config() is asynchronous i.e. it won’t block until an IP was assigned. You really need some sort of timer interval as shown in our docs. Alternatively you could use the more modern approach and register for WiFi events, see nodemcu.readthedocs.io/en/latest/en/modules/wifi/#wifistaeventmonreg.

  4. Hi can you try an example on how to controlle 5v ws2812b leds and matrix over wifi? or even controle glediator easy via esp8266.

  5. Gentlemen Good day
    Some time ago I read an article regarding the control of LEDs. A module was recommended in the article, so I rushed off and bought one:
    Digital TM1638 8 Bits LED Keyboard Scan And Display Module Digital Tube ST
    At the time of reading the article, I thought I had saved the instructions on how to use this module.
    Of course, now I come to look for them…can’t find them. Can you help me please?
    Many thanks

  6. cool explanation. Thanks for that.
    One question for a beginner: Why do I have to use a resistor on the gate of the mosfet and how do I have to calculate the size of 1k?

  7. Please be aware that the transistors you use are limited to 600mA, this can be an issue with long or power hungry strips.

  8. He Rui,

    I have tryed this now on different nodemcu e12 but the sum is always the same.
    It connects to the wifinetwork and I can surf to the page but then …
    It never changes a color of the ledstrip!
    I can click on the color field in the page, change the hex numbers and push the button but the is no action in the ledstrip.
    There is always 0.41 volt on the blue wire. 0.84 on the green and red wire.
    I flashed the nodemcu e12 with : nodemcu_float_0.9.6-dev_20150704 and even let a flash fill make by a thirth party but, like I said before, the sum is always the same.
    Something is wrong but have no clue any more.
    Do you have any idea?


  9. Hi,

    I noticed that this exaple with rgb led only works using Your firmware from August 2016. With new firmware the webserver does not work properly. Of course I have changed ssid and pwd in a table and have the firmware made using the same modules.. The webserver changes colors, but cannot be called anymore by the IP-adress.

    I would be very interested in a solution

    Regards Derek

    • Hi.
      You’re probably right. We haven’t tested this example for a while.
      At the moment we don’t have time to update the code.
      The method to create the web server with the new version of the firmware might be slightly different now.
      So, try to look for a web server example that works with the most recent firmware version and then, try to modify this example to make it work with the new version.

  10. Hi

    first of all nice project.
    What do i need to modify to run the same with 24V?
    What are those values and where you get them from?
    pwm.setup(5, 1000, 1023)
    pwm.setup(6, 1000, 1023)
    pwm.setup(7, 1000, 1023)

  11. That step down converter has IN+, IN-, OUT+ and OUT-, but you only need to connect one cable to the esp and one to the power source. Should they be connected to IN+ and OUT- or how does that work?

    • Hi.
      The OUT- should be connected to the ESP8266 GND. And the and IN- should be connected to GND of your power source.

  12. I am always learning from you and I am very thankful for all your posts. I am trying to transform a single 10W rgb led lamp to be controlled via wi-fi. The led board has 3 wires, one for VCC, one for GND, and one for signal. Do you have a graphic on how could I connect it to an ESP8266? As always, thank you in advance.

  13. Gave it a try today and after some trial and error, got it working. Unfortunately I had a bad MCU, but once I realized that, it went pretty smoothly.

    I am a newbie and was wondering if you have further information on how I can adjust the colors. Not sure my LEDs are the best quality and did find the red connection was swapped with the green, but thought maybe there is a way to play around with the settings.

    Thanks much for all you all offer – Bryant


Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.