My son asked if we could add a noise to the door sensor we made a while back, and make it log the data instead of sending email. I suppose he’s been getting a lot of email recently.
This is apparently in an effort to prepare for Christmas, where he’s hoping to detect if Father Christmas opens his door. I’ve got a while to decide whether I’m going to take the Web system offline on December 24th or let him discover a blip in the data.
Anyway, it’s really easy to get the ESP8266 to run a piezo. You can connect up a buzzer to any digital pin, set it as an output and use the analog write function. We had a bit of fun choosing the tones to play.
I then suggested we put a switch in to turn the sound off. I had one lying around which was suitable, so we just used it to disconnect the piezo from the ground rather than doing a software switch, which requires a resistor and coding. It was a nice opportunity to talk about the trade-off of using a relatively expensive switch which needed mounting on the box instead of a microswitch and needing to write some software.
Next, I updated the server to store the data in DynamoDB and added a Web view. You can put any day into the day parameter on the querystring, and it will show a plot of the opening and closing of the door, or it displays data from the current day. I added extra data into the DB that might allow for secondary indices to produce per-week, or year summaries later, but I haven’t done anything with it.
Finally, the box itself got a paint job.
The updated code is below: