I’m on holiday this week, so I’ve had a chance to do some fun stuff at home. My 8 year old son saw the Google Nest products on YouTube and wanted to create his own version with a Raspberry Pi with a camera module.
Rather than spend £30 on a Raspberry Pi, £12 for a camera module etc., I suggested we could build a minimal viable product first using a much cheaper ESP 8266 (£3) hooked up to a reed switch on the door, plus I had one lying around. I ordered a reed switch from Amazon for £2.
First step was to get the ESP 8266 to react to switch events on a digital input. We got it working based on this https://www.arduino.cc/en/tutorial/switch - but instead of lighting an LED, sending the switch status using
Serial.write and using the Ardiuino IDE Serial Monitor to check it worked.
Once it was printing to the console, I set the API up to email him when the API receives a POST.
At this point, we had an API and the ESP 8266 handling switch notifications, the next part was to get that ESP 8266 onto the home wifi, and send a POST notification to the API.
Here’s all the code:
I simplified the micro-controller code by using a few libraries. A debounce library to handle switch noise, and a HTTPS RestClient library, since the default doesn’t support HTTPS. Since there’s hardly any RAM and no disk, there’s no space to store information about valid root certificates etc. For a toy project, there’s no need to protect against invalid or expired certificates.
Once we had it working on the table it was time to upscale it. I bought 25m of doorbell cable from the local ScrewFix for £3, and soldered the ends of it onto a bit of stripboard I had lying around, along with the required resistor. I did this more for the fun of introducing my son to soldering than anything else, because we could have just used a connector block for a single resistor and a couple of cable connections.
Then, we put it in an ice cream tub to make it more professional.
So, we’re onto the final step - installation and decoration of the box!
Of course, I already had a few pre-requisites (laptop for coding, multimeter for testing, screwdrivers, optional soldering iron) but the parts themselves cost less than £10:
- ESP 8266 - £3
- Breadboard - £2
- Cable - £3
- Switch - £2
- Ice cream tub - free