One day a surface mounted power socket burned out in the room. The hot wire touched the ground pin. The socket turned black on the inside, but remained untouched on the outside. I've replaced it with a new one, and for some reason, I didn't throw away the damaged one. I started to think about what can I do with it.
I realized that the holes on the socket are exactly 5 mm in diameter. What are 5 mm in diameter too? Of course, LEDs! So I cleaned the socket as I could, drop in some LEDs and other parts and turned it into an internet connected mood lamp. This guide is about how I've done.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Gather Materials
To build your own IoT mood lamp, you will need the following parts:
- 1 x Surface mount power socket
- 1 x ESP-12E or other ESP8266 variant with enough GPIO to drive 6 different pwm channel
- 1 x 5V to 3.3V power regulator module
- 4 x common anode RGB LED
- 1 x ULN2003A transistor array
- 2 x 22 ohm resistor
- 4 x 68 ohm resistor
- 1 x Micro usb socket
- 4 x Dupont jumper head + female terminal
- 1 x Prototype PCB
- 1 x USB-TTL converter module
- 2 x Styrofoam ball
- Jumper wires
- Soldering iron
- Third hand
- Utility knife
- Hot glue gun
And also to program the ESP, you will need
- Arduino IDE
- Driver for USB-TTL converter module
Step 2: Schematics
I used a standard micro USB socket to power the lamp. This way any USB charger, external battery pack or even a notebook can be used as power source.
The problem is that USB provides 5V DC. It's okay for the LEDs with resistors, but the ESP8266 requires 3.3V DC, so I used a 5V to 3.3V regulator module I had bought on ebay.
ESP8266 has 12mA drive capacity on each GPIO pin. This is not enough for driving the LEDs directly. For this reason I'm driving the LEDs through a transistor array.
I put in a 4 pin connector because I wanted to flash the ESP or read/send debug messages at anytime without disassemble the lamp. Tx, Rx pins are required for the serial communication, GPIO0 is for instruct the ESP to start in flash mode, and GND is also required if the lamp and the serial converter powered by a different power sources.
Adding a 5th external connector or a button for reset can be a good idea too.
Step 3: Solder It Together
There is not much space on the inside of the socket and I wasn't sure if the parts soldered to a single pcb can fit in, so I left everything as modules and wired them together with a lot of wire. This way I can distribute the parts in the available spaces around the holes.
To wire the parts I used single core wires from an old UTP cable. For the first try this led to a massive chaos because of the lot of individual wires. If you have ribbon cables then use it. It will make your life easier. Or if you have single wires too, then just twist the wires which goes to the same module. This trick can bring order to the chaos.
Step 4: Assemble
First of all I threw away all the useless parts except the housing, back plate and two screws.
The assembling was really easy. I've just dropped the modules into the socket and the rigid wires kept the whole stuff in place.
There was two part that was tricky. The USB socket and the dupont heads. They need additional cutouts on the side of the socket. Mine already has cutouts. I just widened a bit with an x-acto knife to be able to fit in the connectors.
I had 4x single dupont headers, but my cutout screamed for a 4x1 block. To build it I used one of the makers' best friend, the mighty hot glue. When I need to keep little things in fix position I used to grab them with pliers and press the handles with a rubber band. I used this method to keep the headers together while I glued them.
Of course the hot glue is highly suitable for attaching the connectors to the socket's wall.
Step 5: Flash
Prepare Arduino IDE
To upload the program and data to your ESP you will need Arduino with ESP8266 platform package and ESP8266 filesystem uploader.
You can find installation guides on the following links:
Download the source
You have two options at this point. You can download the version what I've made this instructable for. Here is the download link for the zip.
Or here is the latest greatest version for the brave ones. This might be unstable or incompatible with this post, but probably contains more shiny features.
Modify WiFi access
Open moodlamp/moodlamp.ino in Arduino, find the following lines and modify to match with your WiFi network.
const char* ssid = "<your_ssid>";
const char* password = "<your_wifi_password>";
Flash the program
- Setup the board in Arduino
- Tools -> Board -> NodeMCU 1.0 (or something else matching your board)
- Tools -> Port -> Select your virtual serial port for the USB-TTL converter. In my case it's /dev/ttyUSB0
- I think the other settings are OK on default
- Connect Rx, Tx and GND connectors to the USB-TTL converter (note that the ESP's Rx should connect to the serial converter's Tx, and Tx to Rx)
- Connect GPIO0 to GND (ESP will start in flash mode if GPIO0 pulled down during power up)
- Connect USB power
After flashing the ESP will automatically start the program. You can follow the initialization on the Serial Monitor. LEDs will turn to green if the lamp connected to your WiFi, or to red if something went wrong. In this case you will see an error message on the Serial Monitor.
Storage of the ESP contains two partitions. One for the program, and an additional data partition. In my case it means 1M program and 3M SPIFFS (data). Contents of the moodlamp/data folder goes into a SPIFFS image, then uploaded with the Filesystem plugin.
- Start the board in flash mode as before
- Connect Rx, Tx, Gnd to serial, and GPIO0 to GND if disconnected
- Power on the ESP
This might take a few minutes depending on the baud rate. If everything is OK, the ESP will start again and connect to your WiFi.
Now you have a fully functional mood lamp.
Step 6: Try Out
Open Arduino Serial Monitor, disconnect GPIO0 pin, then restart the lamp (disconnect then connect power). At the end of the initialization the lamp will print its IP address. It will be something like
"[SETUP] MoodLamp is ready to use at 192.168.1.102:80"
If you open this address in your browser, you should get an interactive page where you can set the LED's color and control the rainbow animation.
I could recommend the http:///help page, where the available API calls are shown. They all must be interpreted as HTTP GET requests. For example:
Step 7: The Light Dome
In this stage the lamp is almost done, just need something on top to scatter the light. Endless number of solutions could be guessed. It's on your fantasy, but I can give you some ideas that I tried.
Try #1 - A/5 paper tube
For first I took an A/5 paper sheet and bent into a tube. Fixed with transparent tape and stuck into the lamp.
Try #2 - 5cl plastic glass
The plastic glasses are a bit wider than needed, so I've cut a little from both of them. Joined the two piece together, fixed with transparent tape then dropped to the top of the lamp.
Try #3 - Styrofoam ball
In a nearby shop I found perfectly fitting styrofoam balls that I cut into half, then scraped out the inside. It's more compact and stable than the other solutions. And also it has a nice bubble pattern. That's my favorite.
Participated in the
Arduino All The Things! Contest