This project uses the ESP8266 chip, which can connect via Wi-Fi, allowing you to remotely control the color of the RGB LED mood light using a smartphone or other terminal devices with a browser. It is a DIY project that costs less than $10.Before starting, we need to understand information related to the ESP8266 and RGB LED, such as the working principle of RGB LEDs, ESP8266 RGB color picker, ESP8266 web server with NodeMCU, and NodeMCU firmware flashing.The BOM for this project is as follows:(1) 1x ESP8266-12E Wi-Fi development board(2) 1x RGB LED light string(3) 1x 12V power supply:(4) Voltage regulator to step down from 12V to 5V, such as an LM7805 amplifier (optional), buck converter (recommended), 3x NPN transistors 2N2222 or equivalents, 3x 1k ohm resistors, 1x breadboard, jumper wires, a lamp that looks like a mood light, and a white light bulb.1. Flashing the NodeMCU firmware on the ESP8266 moduleNodeMCU is a firmware that allows programming the ESP8266 module using LUA scripts, similar to programming on Arduino.Programming NodeMCU is quite simple, requiring just a few lines of code to establish a Wi-Fi connection, control the ESP8266 GPIOs, and configure the ESP8266 as a web server.The connection parameters for the ESP8266 module circuit are as follows:RX -> TXTX -> RXCH_PD -> 3.3VGPIO 0 -> GNDVCC -> 3.3VGND -> GNDAfter connecting the ESP8266 module according to the circuit diagram, download the Windows version of the NodeMCU Flasher. This is actually an .exe file; open it, and a small window will appear. Press the “Flash” button to start the flashing operation immediately. Of course, you can also click on the Advanced tab to change some parameters and settings before operating.Once this operation is complete, a green circle with a check button will appear.2. Download ESPlorer IDEIt is recommended to use ESPlorer IDE for downloading. This program developed by 4refr0nt can send commands to the ESP8266 chip, and the specific download and installation instructions are provided by Espressif’s official website.After installing ESPlorer IDE, a window will pop up to upload code. You can upload files by following these instructions:(1) Connect the built-in programmer ESP8266-12E to the computer.(2) Select the ESP8266-12E port.(3) Click the Open/Close option.(4) Select the NodeMCU+MicroPython tab.(5) Create a file named “init.lua”.(6) Click the Press Save to ESP option.Note that the uploaded code file must be named “init.lua”. Be sure to remember your network name (SSID) and password.The following script was created in 2016 and is only suitable for early versions of Lua firmware. If running a new version of the Lua firmware, you must use the ESP8266_RGB_Color_Picker_New.lua script:
-- Rui Santos-- Complete project details at https://randomnerdtutorials.comwifi.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)endpwm.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..""; buf = buf..""; buf = buf..""; buf = buf..""; buf = buf..""; buf = buf..""; buf = buf..""; buf = buf.."ESP Color Picker"; buf = buf.."Change Color "; buf = buf..""; buf = buf..""; 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
3. Connecting the CircuitAccording to the circuit diagram, connect the ESP8266-12E Wi-Fi development board, RGB LED light string, 12V power supply, and NodeMCU together.Restart the ESP8266, and the system will automatically print your serial number and ESP IP address. Save this IP address for future use. The ESP IP address for this project is 192.168.1.105.Next, open your browser and enter your ESP8266’s IP address, and you will see:RGB color picker main selecting colorClick the input field to open a small window with a color picker. Use the mouse to select a color for your RGB LED script.Finally, select the “Change Color” button.Now, you can move this DIY Wi-Fi controlled RGB LED mood light into your bedroom.
*Source from Breadboard Community, author: Hard City Allchips, EDNC Electronic Technology Design has been authorized for reprint.