DIY WiFi RGB Floor Lamp - Ikea Hack

by bhaveshtk in Circuits > LEDs

7893 Views, 112 Favorites, 0 Comments

DIY WiFi RGB Floor Lamp - Ikea Hack

Screen Shot 2022-03-01 at 2.32.04 PM.png

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

Hacking an IKEA lamp with glorious Neopixels - ESP32 MicroPython tutorial

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

Screen Shot 2022-03-01 at 1.34.08 PM.png

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

Screen Shot 2022-03-01 at 1.23.58 PM.png
  1. Connect the resistor in series between your selected data pin on the ESP32 and the data line on the Neopixels strip connector.
  2. Connect the capacitor between 5V/USB power pin and ground pin.
  3. 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

Screen Shot 2022-03-01 at 1.40.10 PM.png

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!

Screen Shot 2022-03-01 at 1.51.12 PM.png

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)

Screen Shot 2022-03-01 at 2.14.25 PM.png

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

Screen Shot 2022-03-01 at 2.08.11 PM.png
  • 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!

blue-dabadee-neopixels.gif

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