DIY WiFi RGB Floor Lamp - Ikea Hack
by bhaveshtk in Circuits > LEDs
8139 Views, 114 Favorites, 0 Comments
DIY WiFi RGB Floor Lamp - Ikea Hack
Hello, hardware hackers! MicroPython is an exciting new way to code Neopixels because it allows us to try different light patterns and algorithms quickly without having to compile the code (unlike Arduino). In addition, MicroPython comes with awesome tools like WebREPL which allow us to upload new code to the microcontroller remotely over WiFi!
You'll first learn the hardware setup for safely connecting an ESP32 to two Neopixel strips, and embedding that inside an IKEA lamp. Then we proceed to code basic RGB light control and HSV light control, followed by implementing an awesome "Niagara Falls" rainbow animation! Finally we learn to use WebREPL to upload and run code remotely over WiFi so that the project can be powered independently of your computer.
Supplies
(See Step 2 below for supplies list)
Watch the Video
The descriptions of all the steps below assume that you have seen the video to understand the process of building this project. So please watch it first!
Procure Materials
- IKEA Vidja floor lamp: https://www.ikea.com/ca/en/p/vidja-floor-lamp-white-10309206/
- ESP32: https://www.amazon.ca/KeeYees-Development-Bluetooth-Microcontroller-ESP-WROOM-32/dp/B07QCP2451
- High-current (more than 3A) USB power plug: https://www.amazon.ca/Charger-Fasgear-Adapter-Charging-Compatible/dp/B083NLR4G6
- Neopixels/WS2812B strip: https://www.amazon.ca/BTF-LIGHTING-Individually-Addressable-Flexible-Non-Waterproof/dp/B01N5ATQZT
- Light strip connectors: https://www.amazon.ca/BTF-LIGHTING-Connectors-WS2812B-WS2811-WS2812/dp/B01DC0KIT2
- A resistor between 300-500 ohms and a capacitor between 500-1000uF, according to Adafruit's guide (https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices). You can get these at any electronics shop, usually as part of a kit of resistors and capacitors but sometimes available individually.
Lastly, make sure to download Thonny IDE (https://thonny.org/) as we will be using it to program the ESP32 in MicroPython later.
Solder or Breadboard the Parts and Connectors Together
- Connect the resistor in series between your selected data pin on the ESP32 and the data line on the Neopixels strip connector.
- Connect the capacitor between 5V/USB power pin and ground pin.
- Connect the Neopixel connector's power line (red) to 5V/USB pin, its ground line (green) to a ground pin, and its data line (white) to the resistor.
Note that the image shows 2 Neopixel connectors because I used 2 strips in my project for extra bright lights. If you want to do the same, just repeat step 3 with another Neopixel connector so that both connectors are connected in parallel on all 3 pins.
Peel the Backing on the LED Strips and Stick It Inside the Lamp
The bulb is not needed for this project, but it can happily live side-by-side with your LED strip(s).
Connect the ESP32 to the Neopixels and to Your Laptop
Connect to the Neopixel strip(s) via the 3-pin connectors you soldered on earlier. Connect to your laptop via a micro-USB to USB cable.
Write the MicroPython Code and Upload!
To see your light patterns in action powered over USB from your computer (i.e. not over WiFi yet):
- Save the file main.py onto your board using Thonny IDE.
- In the Shell pane at the bottom of Thonny IDE, type in:
import main main.setRGB((255, 0, 0)) main.setRGB((0, 255, 0)) main.setRGB((0, 0, 255))
to ensure each of your 3 LED colour channels (red, green and blue) are working properly. You should see your light come to life with these 3 colours. Make sure to use double brackets around the values!
For extra fun, try typing in the code:
main.niagara()
This will create an awesome scrolling RGB pattern on your lights, just like Niagara Falls at night! To stop the pattern from running and be able to write more commands in the Shell, hit Ctrl+C.
Downloads
Set Up WebREPL on the ESP32
In the Shell at the bottom of Thonny, type in this command to set up WebREPL:
import webrepl_setup
It will ask you to set up a password so that you can securely access your ESP32 remotely over WiFi later.
Set Up WiFi on the ESP32
- In Thonny, create a file called secrets.py on your ESP32 with the following contents:
WIFI_NAME = 'your-wifi-name/SSID-here' WIFI_PASS = 'your-wifi-password'
where you replace the strings with your actual WiFi name/SSID and password, of course.
- In Thonny, replace the file boot.py on your microcontroller with the one attached here. Now when you restart your ESP32, it should automatically connect to your WiFi router on boot up!
- Restart your ESP32. In the Shell in Thonny, type in these command to get your ESP32's IP address:
import boot boot.connect()
Note down this IP address as we'll use it later to connect over WiFi.
Downloads
Connect ESP32 Power to the Wall (instead of Laptop)
Remove the ESP32's USB cable from your laptop and connect it instead to the USB wall outlet your purchased. We don't need a direct connection to it anymore as we'll be using WiFi to control it from now on!
Download the WebREPL Web Interface and Connect
- The WebREPL web interface source code is on github. I have linked it here as a zip folder download for your convenience, if you don't have git and/or don't know how to use git and github.
- Download and unzip the folder.
- Go into the resultant folder (should be named 'webrepl') and open the file webrepl.html in your web browser.
- You should see an interface with a shell/REPL on one side and a file uploader/downloader on the other side.
- Type in your IP address (from earlier) at the top-left corner of the REPL and click 'Connect' button.
- You should see a password prompt. Enter your password - you are now accessing your ESP32 remotely over WiFi!
Run Animations, Upload New Code, Enjoy!
You now have WiFi access to your RGB lamp, using WebREPL! Send any commands you want, make changes to main.py and upload them, and reset the microcontroller using the 'machine.reset()' command. The world is your oyster!
If you enjoyed this Instructable and want to see more of my hardware and code tutorials, visit https://bhave.sh 🤩
To see my updates and get more insight into my thoughts and process, follow me on Twitter 😃
If you would like more background on Neopixels/WS2812Bs to understand how colour mixing works and how to create your own awesome custom HSV colour patterns, check out my in-depth tutorials on my website: Part 1 and Part 2