Wi-Fi Light Switch
You'll put an ESP board on your home network, serve a web page from it, and flip an LED and read a sensor from your phone.
About
An ESP8266 or ESP32 is a microcontroller with Wi-Fi built in, for five to ten dollars. Put it on your network and it can serve a page, and anything with a browser becomes a remote control. You'll toggle an output and show a sensor reading from your phone, which is the seed of every smart-home gadget you've ever bought. Keep it on your own network only. Opening a port on your router to reach it from outside is a bad idea and off limits for this badge.
At a glance
- Per requirement
- 15 XP
- Completion bonus
- 75 XP
- Requirements
- 5
- Takes
- One evening
- Skill level
- Beginner (done it a few times)
- Cost
- Inexpensive (under $20)
- Supplies
- You need some
- Where
- At home
- Other people
- On your own
Requirements
-
1
Join an ESP8266 or ESP32 to your Wi-Fi and print its IP address. Add the board to the Arduino IDE through the boards manager, or use MicroPython's network module. Put your Wi-Fi password in a separate file or at the top of the sketch where you'll remember to remove it before you share the code. These boards only do 2.4 GHz, so if it never connects, that's the first thing to check. Take a screenshot of the serial monitor showing the IP address. Photo
-
2
Serve a page with two buttons that turn an LED on and off. The WebServer example gets you most of the way. Each button hits a URL like /on and /off and the handler sets the pin. Film your phone toggling the LED. Video
-
3
Show a live sensor reading on the page that updates without a reload. Serve the reading as plain text at /reading and have a few lines of JavaScript fetch it every two seconds. Temperature, light or a door switch all work. Film the number changing on the phone while you cover the sensor. Video
-
4
Give it a name on the network and a fixed address. Use mDNS so you can type esp-switch.local instead of a number, or reserve its address in your router. Take a screenshot of the page loaded by name. Photo
-
5
Switch something that matters with a relay or a MOSFET, low voltage only. A 12 V LED strip, a USB desk fan through a MOSFET, or a 5 V relay module switching a 12 V pump. Nothing on this badge touches mains. Mount it so it stays put. Take a photo of it in place with the page on your phone beside it. Photo