My first “serious” Blynk project
It’s nothing spectacular or groundbreaking. It’s yet another ESP8266 (12F) reading a DS18B20 temperature sensor. But, I figured I’d post in case someone finds it useful.
- Most settings are
#definedat the top of the sketch, so it’s easy to “tweak” them. I’ll put the values I’m using in parentheses ().
#defineis used to select Celsius or Fahrenheit.
- Temperature is read and reported at a fixed interval (30 seconds).
- The sketch will alert if the temperature goes to low or too high. The low and high temperature points are set by app widgets (pins V2 and V3). (I use the step control widget but a slider, or anything that can send an integer value to a virtual pin, could be used). To alert, the sketch will send a push notification and also change the color of the widget that displays the temperature to (blue) for low or (red) for high. The widget color will be changed to (green) when the temperature returns to within the normal range
- Blynk.syncAll() is used to keep the alert values in sync between the app and the device whenever the device connects to the server, in case the values are changed while the device isn’t connected.
- A hysteresis value (3 degrees) is added to the low and high alert values to prevent frequent multiple alerts if the temperature fluctuates around the low or high set point.
- An LED (the ESP8266’s on board blue LED) is used to indicate status:
- A very brief flash (30mS) each time the temperature is read successfully (every 30 seconds).
- A long flash (5 seconds) if the temperature read is not successful.
- Rapid blinking (200mS every 500mS) if the sensor isn’t detected when the sketch starts up.
- A long flash (2 seconds) if the connection goes down. This flash occurs each time Blynk tries to reconnect but is unsuccessful, which is about every 9 or 10 seconds.
- The temperature is sent on two virtual pins (V0 and V1). The same value is sent on both pins but one (V0) also sends widget color changes for low and high alerts. I use a gauge for (V0) and a history graph for (V1).
- The sketch is well behaved in terms of Blynk guidelines. Timers are used to control sketch operation. Even the required “wait for sensor temperature conversion” (800mS) is handled by a timer, instead of a delay, which I haven’t seen any other DS18B20 Blynk sketch do. There are some delays used but only for status LED timing in places that won’t affect the proper operation of the Blynk library.
UPDATE: I’ve added tracking and display of the minimum and maximum temperatures and the ability to reset these. See my later post in this topic for a screen shot.
- The minimum and maximum temperatures reached are sent on virtual pins (V4 for min, V5 for max) whenever they change. A virtual pin (V6 ), which receives a boolean value, is used to reset these. I used labeled value widgets for displaying and a momentary button for resetting.
My app layout
This screen shot is scrolled down. When scrolled up, the gauge is fully displayed and the step control and notification widgets are off the bottom and not visible, at least on my phone.
I used a bare ESP8266-12-F module. I mounted and wired it on a piece of prototype board along with a 3.3V regulator, reset and program buttons, and the necessary resistors and capacitors. The red LED just indicates 3.3V power.
Power comes from a 5V charger supply for an old Samsung cell phone (with the connector removed and the wires hard wired to the circuit board).
The DS18B20 is wired to the end of a short length of solid core wires so it can be positioned away from the heat generated by the circuit board.
The case is from a (used) pack of dental floss, with Velcro used to hold it more securely closed.
The sketch code, and a schematic of the hardware created with KiCad, are available on GitHub