Skip to content

WeMos+DS18B20 thermostat with logging

License

Notifications You must be signed in to change notification settings

netphantm/Arduino_thermostat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DS18B20 thermostat with logging

header

ESP8266 thermostat with DS18B20 oneWire sensor

This is a 'simple' thermostat controller, using a DS18B20 oneWire temperature sensor on a WeMos D1 Mini Pro. The DS18B20 has a +/-0.5 °C tolerance and is perfectly stable (and even cheaper). I tried it first with an DHT11 sensor, but it's very unreliable, unstable and has a +/-2 °C tolerance (and who needs a humidity sensor anyway, except perhaps if you use it in a sauna).

It uses two relays for safety reasons, to be sure that there is no current on either one of the power lines when switched off. I couldn't find a shield with two relays, so I bought it as a kit and soldered all components to the board myself (relays, terminal strip, and the fun part: the SMD components). It just had to be rewired to switch two separate wires independently, instead of switching current from the same wire to two different consumers.

The thermostat will power up the relays if the temperature is greater than temp_max and power off if temperature falls below temp_min if the appliance is set as a cooler, and accordingly, power them up if temperature falls below temp_min and power off if the temperature is greater than temp_max if set as a heater.

The www branch contains the (php) files needed for the webserver (get log data, keep settings, render Google graph, provide a settings form for one or more such devices). In the settings form, some standard values are filled in, some basic checks performed and the SHA1 fingerprint is calculated from the server's certificate (to make sure the WeMos sends the data to the right logserver).

The display shows following data: the SSID (if connected to WiFi, or the IP and credentials for the AP it provides in config mode), the LAN IP, the outside IP (which it refreshes only once an hour, to not get banned from ipinfo.io), the temperature (also min/max on the large display), the device type (heater/cooler), the relais state (On/Off) and the current operating mode (manual/automatic).

A capacitive touch sensor toggles the relay if pressed less than 500ms thus changing to manual operating mode (means that relais isn't controlled by the temperature readings anymore). If held longer than 500ms, it switches back to automatic mode. I used touch sensors because I didn't have buttons, but it's way cooler with touch sensors anyway. The main advantage is, you don't have to bore holes for the buttons, just stick them to the inner side of the enclosure and add appropriate stickers to the outside.

I know that there are simpler or fancyer methods to do some of this (like OpenHAB, Blynk, etc.), but I wanted to do it all by myself with already available services, as an exercise, and to learn stuff in the process (so please don't contact me with such tips). All other feedback is welcome.


Table of Contents


Features

  • .96" B/W or 1.44" color TFT display for: SSID, LAN and internet IP, temperature, mode (man/auto) and relay status
  • Uses WiFiManager library, so you don't have to hardcode the WiFi credentials
  • Uses a webserver to log the measurements (HTTPS)
  • Compares the logservers certificate SHA1 fingerprint with the one provided in the settings
  • Progress bar on the serial console, showing time percentage until next log update
  • Manual relay override via capacitive touch sensor; press longer than 1s to switch back to automatic mode
  • Option to change between 'cooler' and 'heater' thermostats (fire up on temp >= temp_max or temp <= temp_min)
  • Draws a google graph from the logged data and a gauge which also shows hysteresis
  • Shows last update date/time in the browser's timezone
  • Settings button on the webpage, which opens the device's settings page
  • Provides a setup page for configuration variables that are sent to the WeMos, which then stores them as JSON to the webserver and SPIFFS:
    • WeMos D1 hostname (in case you have more than one device logging to the same webserver)
    • SHA1 fingerprint (calculated by the php script from localhosts certificate)
    • Logserver hostname
    • Logserver port (HTTPS)
    • Refresh/sensor reading interval
    • Minimum/maximum temperature values for the hysteresis
    • Temperature deviation for calibrating the sensor
    • Thermostat device type (cooler/heater)
    • Operation mode (manual/automatic)
    • Time interval between measurements.

↑ goto top


Libraries needed

  • WiFiManager
  • ESP8266HTTPClient
  • ESP8266WebServer
  • ESP8266mDNS
  • FS
  • OneWire
  • DallasTemperature
  • ArduinoJson
  • Adafruit_GFX
  • Adafruit_ST7735
  • SPI
  • TFT_eSPI

↑ goto top


TODO

  • Clean up code and add comments
  • CSS-styled mouseover tooltip for the graph, including relay status
  • Change the graph's time range, enable zooming and panning
  • Change the horrible design (now I've added even more of it)
  • Responsive design for mobile devices
  • (Perhaps) Enable OTA
  • (Perhaps) Keep log data in a local file if logserver is not reachable and send it all when connectivity is restored
  • (Perhaps) Documentation, including 'fritzing'. In the mean time, look at my sources in the Links (software) below (fritzing should be pretty straight forward anyway)
  • (Perhaps) Change checking logserver validity from comparing SHA1 fingerprint, to check against an uploaded CA certificate (longer validity then a letsencrypt signed certificate)

↑ goto top


Bugs

  • .96" Display won't work if not initialized just before use (init should happen only once, in setup()).

↑ goto top


Links

Hardware

Software

↑ goto top


Images

pic-01 pic-02 pic-03

pic-04pic-05

pic-06pic-07
pic-08pic-09 pic-10

↑ goto top

Screenshot graph page

screen-01

screen-02

Screenshot settings page

screen-03

Screenshot console log

screen-04

Screenshot device response

screen-05

Screenshots device WiFi configuration

screen-06screen-07

↑ goto top


License

License

↑ goto top