diff --git a/content/posts/medicine_indicator_light.md b/content/posts/medicine_indicator_light.md index 22be11c..035ef58 100644 --- a/content/posts/medicine_indicator_light.md +++ b/content/posts/medicine_indicator_light.md @@ -1,11 +1,11 @@ --- title: 'ESP8266 Medicine Indicator Light' -date: 2023-10-13T15:49:14-04:00 +date: 2023-10-16T11:34:14-04:00 tags: ["diy", "tutorial", "esp"] author: "Me" showToc: true TocOpen: false -draft: true +draft: false hidemeta: false description: 'Learn how to make an ESP8266 and a few simple components into an indicator light.' disableHLJS: true @@ -28,18 +28,23 @@ cover: --- This is a quick treat! We recently learned that one of our children needs to take medicine twice a day for the foreseeable -future. He's too young to take it on his own, and the morning and evening responsibility are split up between my partner and -I, so we needed some sort of indicator to let the other know if the previous dose was (or wasn't!) taken. Naturally, I sprung -into action with an ESP device and some leftover components. +future. He's too young to take it on his own, so the twice-a-day responsibility is split up between my partner and +I. However, sometimes our schedules don't overlap so succinctly, so we needed some sort of indicator to let the other know if +the previous dose was (or wasn't!) taken. Naturally, I sprung into action with an ESP device and components. ## Device Overview -The device works like this (see the pictures below): Two [single neopixel LEDs](https://www.adafruit.com/product/1260) and a -non-latching button are connected to the ESP8266. Inside the code there is a switch-case section which changes case per -button press. On each press, the light will change depending on what is setup for that case. At the same time, each case is -establishing a value for `morning` and `evening` which will be given a value of 0 or 1 - 0 to indicate that the medicine was -not taken, and 1 to indicate that it was taken. Along with the time server data, I send an MQTT payload to my [MQTT Broker, -Mosquitto](https://mosquitto.org/). +The device works like this ([see the pictures below]({{< ref "medicine_indicator_light.md#pictures" >}})): Two [single neopixel LEDs](https://www.adafruit.com/product/1260) and a +non-latching button are connected to the ESP8266. Inside the code there is a [switch-case](https://www.arduino.cc/reference/tr/language/structure/control-structure/switchcase/) +section which changes states per high/low state of the button. On each press, the lights will change to one of the following: + +* Red/Red +* Green/Red +* Red/Green +* Green/Green + +For each case, I established a values for `morning` and `evening` which will be given a value of 0 or 1 - 0 to indicate that the medicine was +not taken, and 1 to indicate that it was taken. Along with the time server data, I send an MQTT payload to my [MQTT Broker](https://mosquitto.org/). Here's what the payload looks like: @@ -53,27 +58,28 @@ Here's what the payload looks like: ## Thoughts and Background -I'd like to write a longer post that chops up to the code and goes into explanations of each section, but I'm running out of +I'd like to write a longer post that explains each section of the code, but I'm running out of time - work has been quite busy lately. If you'd like me to add a post with more code explanations, or just have questions, feel free to mention me on [Mastoton/Fosstodon](https://fosstodon.org/@notnorm) and we can chat. -The much shorter explanation is that I didn't want this device to be an isolated device in my network. So what I did was -connected the ESP8266 to my wifi network and import an NTP (Network Time Protocol) server to ensure I get I have the current -time. Then, look at the state of the light, and construct and transmit an MQTT payload with the state of the light & time, so -that I can use it elsewhere. +The much shorter explanation is that I didn't want this device to be an isolated device in my network; this was part of the +impetus in using an ESP device as opposed to another microcontroller. So what I did was connected the ESP8266 to my wifi +network and imported an NTP (Network Time Protocol) server to ensure I get I have the current time. Then, look at the state +given by the case (and thus the external light indicator), and construct and transmit an MQTT payload with the state of the +light & time, so that I can use it elsewhere. In other words, now with MQTT payloads being accessible to HomeAssistant, I can +send myself a notification, or make an announcement on a speaker. What's neat about importing a time server is that at midnight, I reset both of the lights to red so that I don't have to reset it manually when I get up in the morning. In a separate post, I'll show how I use the MQTT payload in HomeAssistant to send [Pushover Notifications](https://pushover.net) -to me and my partner in case we forgot to give my child his medicine! What's great about this little project is that it is -scalable (add more components and sensors!) and that it doesn't need to indicate if someone has taken their medicine! You -could use the button to count how many times your dog (or child!) has gone to the bathroom, how many times to eat a snack or +to me and my partner in case we forgot to give my child the medicine! What's great about this little project is that it is +scalable (add more components and sensors!) and it isn't limited to a medicine indicator. You +could use the button to count how many times your dog (or child!) has gone to the bathroom, how many times you have eat or drink water while working, and many more ideas. -Assuming everything has gone well for the day and we've given my child both of his doses, we should -be heading to bed with both of those lights being green. However, we'll want to take into account a few edge cases. See the -pictures below with quick explanations. +Assuming everything has gone well for the day and we've given my child both doses, we should be heading to bed with both of +those lights being green. ## Materials Used @@ -89,10 +95,14 @@ Here is what I used to construct this: ## Pictures - - - - +
+
+
+
+