The past few weeks have seen me hacking together a number of small projects from Conway's Game of Life on an OLED screen to an informational bot giving real-time radar information for Amazon Alexa. Today I'm sharing a project I recently put some finishing touches on: Alexa voice-control for lights using nothing more than a NodeMCU. The firmware code is based largely off of someone else's project aimed at getting an Arduino board to do the exact same thing, but I made a few key modifications:
- Major refactor because the original code was both messy and slow (sorry it's true!)
- The GPIO pin is set to voltage up by default (for offline use without WiFi / Alexa)
- Implemented a WiFi Manager, negating the use for hard-coded WiFi credentials
The finished prototype was connected to a single LED, as you can see in the demo video here:
I wasn't entirely sure how I wanted to make a more permanent implementation, but then I noticed I had not one, not two, but five NodeMCUs sitting around in a bin. It thus didn't take long before I'd committed one of them permanently to this project. I also decided to hardwire the end result directly to the end of some string-light LEDs.
Similar to some of my prior projects, I sandwiched the solder connections and wiring between two prototyping boards. This enabled me to wind the cord running to the LED lights around the pins and thus hopefully alleviate stress and prevent the connections from breaking loose.
While I'm not entirely happy with the result- mostly because it would be far too easy for something to short pins on the NodeMCU- it's at the point where any additional work put into it will only result in minimal improvements.
And what would project documentation be without a link to the code repo? You can find it here: https://github.com/ckuzma/nodemcu-as-arduino/tree/master/Sketches/Alexa/AlexaWemoSwitch
- 1 - Download / clone this repo's code
- 2 - Change the device name (by default it is "Christmas Lights")
- 3 - Install additional libraries as needed and then flash the NodeMCU
- 4 - Connect relay device to D1 (or whatever you selected) on the NodeMCU
- 5 - Using another device, connect to the open ESP network to configure your wireless settings
- 6 - Restart the NodeMCU (if necessary) so that it connects to WiFi using the saved settings
- 7 - Scan for new Smart Home devices in the Alexa app
- 8 - Say "Alexa, turn on the christmas lights" (or whatever your device name is)
This sketch began as a fork of Aruna Tennakoon's project using an Arduino D1 Mini as a WeMo switch, and then took on a bunch of modifications of its own. That original project can be found here: https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch