This article describes the construction of a simple thermometer with a DS18B20 sensor. We are ending a board with ESP8266-E12 and integrated OLED display and a Sensor DS18B20 without board. The circuit is very simple and the sensor can be soldered directly to the board.
Circuit:
View:
Since the ESP8266 supports WiFi, I have already built in the sketch the support of a second remote sensor. This second sensor will communicate with the thermometer with ESP-Now, a protocol with which very energy-saving solutions can be created. The measurement results are then displayed alternately on the display. If no remote sensor is connected, only the value of the internal sensor is displayed.
The sketch is commented in detail.
Sketch:
/* Esp8266 with OLED display as thermometer */ Libraries for WiFi #include <ESP8266WiFi.H> Library for OLED Display #include <U8g2lib.H> Libraries for DS18B20 Temperature Sensor #include <OneWire.H> #include <DallasTemperature.H> Library for ESP-Now External "C"{ #include <espnow.H> } Pins for temperature sensor Const Byte Bus = 0;pin GPIO0 Protocol for reading out the sensor OneWire oneWire(Bus); Sensor instance DallasTemperature Sensors(&oneWire); Array to store sensor addresses DeviceAddress Addresses; Initialize display U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ 16); Offset for calibration of temperature Const uint8_t Offset = 15; Values of the temperature sensors -127 = the value, which you get when no sensor is connected Float Outside = -127; Float Inside = -127; After a reset, the SSID is visible so that a remote sensor can be can connect. After about 2 minutes the SSID should be hidden Counter for switching off the visible SSID Int Cnt = 24; Logos as bitmap for display #define haus_width 16 #define haus_height 16 Static Unsigned Char haus_bits[] = { 0x80, 0x0c, 0xc0, 0x0d, 0x60, 0x0f, 0x30, 0x0e, 0x18, 0x0c, 0xcc, 0x19, 0x46, 0x31, 0x47, 0x71, 0xc5, 0x51, 0x04, 0x10, 0xf4, 0x16, 0x94, 0x16, 0x94, 0x16, 0x94, 0x10, 0x94, 0x10, 0xff, 0xff }; #define baum_width 16 #define baum_height 16 Static Unsigned Char baum_bits[] = { 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x10, 0x05, 0x08, 0x0a, 0x34, 0x13, 0x04, 0x10, 0x02, 0x10, 0x02, 0x08, 0x04, 0x16, 0x18, 0x10, 0xd0, 0x17, 0xa0, 0x09, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff }; Data structure for data exchange via ESP Now Struct DATEN_STRUKTUR { Float Temp = 0; }; Network Name Char* Ssid = "Thermometer"; Callback function when data has been received Void on_receive_data(uint8_t *Mac, uint8_t *r_data, uint8_t Len) { DATEN_STRUKTUR Data; we copy the received data to the data structure to be able to access the data structure Memcpy(&Data, r_data, Sizeof(Data)); Outside = Data.Temp; }; function to print a sensor address Void printAddress(DeviceAddress Addresses) { for (uint8_t Ⅰ = 0; Ⅰ < 8; Ⅰ++) { If (Addresses[Ⅰ] < 16) Serial.Print("0"); Serial.Print(Addresses[Ⅰ], Hex); } } Void Setup() { Serial.Begin(115200); Wifi.Begin(); Configuration of the access point Wifi.Fashion(WIFI_AP); Wifi.softAP(Ssid); Initialize ESOP-Now If (esp_now_init()!=0) { Esp.restart(); Delay(1); } SET ESP role 1=Master, 2 = Slave 3 = Master + Slave esp_now_set_self_role(2); and register callback function esp_now_register_recv_cb(on_receive_data); Preparing the display u8g2.Begin(); u8g2.enableUTF8Print(); u8g2.setFontMode(0); Initialize temperature sensor Sensors.Begin(); Serial.Print(Sensors.getDeviceCount(), DEC); Serial.println(" Sensors found."); Now let's check if the bus is in parasitic mode Serial.Print("Parasitic mode is "); If (Sensors.isParasitePowerMode()) { Serial.println("ON"); } else { Serial.println("OFF"); } Now we check if one of the sensors on the bus is a temperature sensor If (!Sensors.getAddress(Addresses,0)) { Serial.println("No temperature sensor available!"); } View addresses Serial.Print("Address: "); printAddress(Addresses); Serial.println(); Sensors.setResolution(Addresses,12); Serial.Print("Resolution = "); Serial.Print(Sensors.getResolution(Addresses), DEC); Serial.println(); Pullup resistance for temperature sensor pinMode(0,INPUT_PULLUP); } Void Loop() { Char Text[50] = {0}; Text buffer for display Int Tmp; Temporary for temperatures Sensors.requestTemperatures(); Sensor measurement start Delay(800);Time to measure the temperature Inside = Sensors.getTempC(Addresses); Reading temperature from the sensor We convert the temperature to integer with a decimal place Tmp = round(Inside * 10); Generate output text Sprintf(Text,"%2d.%0 1d°C", Tmp/10-Offset, Abs(Tmp%10)); and send to display u8g2.firstPage(); Thu { first the logo u8g2.drawXBM( 0, 8, haus_width, haus_height, haus_bits); then the text u8g2.setFont(u8g2_font_osb26_tf); u8g2.setFontDirection(0); u8g2.drawUTF8(20, 30, Text); } while ( u8g2.nextPage() ); Delay(5000); 5 seconds to wait Reduce the counter If (Cnt > 0) Cnt--; Do we have a value from a remote sensor Then we show the If (Outside != -127) { We convert the temperature to integer with a decimal place Tmp = round(Outside * 10); Generate output text Sprintf(Text,"%2d.%0 1d°C", Tmp/10, Abs(Tmp%10)); and send to display u8g2.firstPage(); Thu { first the logo u8g2.drawXBM( 0, 8, baum_width, baum_height, baum_bits); then the text u8g2.setFont(u8g2_font_osb26_tf); u8g2.setFontDirection(0); u8g2.drawUTF8(20, 30, Text); } while ( u8g2.nextPage() ); Delay(5000); 5 seconds to wait Reduce the counter If (Cnt>0) Cnt--; } When counters on 0 hide the SSID If (Cnt <= 0) Wifi.softAP(Ssid,Null,1,1); }
With a suitable LiPo battery with 3.7 V, the thermometer can be operated with battery. The charge controller and battery jack are available on the board.
16 comments
Gerald Lechner
Vielen Dank!
Die Buchse für den Akku an der Untrerseite der Platine ist ein 1.25mm JST 2.
Rahul
Tolles Projekt!
Von dem Aufbau habe ich ein System mit DS18B20 und eins mit DHT22 aufgebaut.
Die loggen ihre Temperatur- (und Feuchte-) Werte auf einem Intranet-Webserver.
Um welchen Steckverbinder handelt es sich bei dem Akku-Anschluss?
Bernd Albrecht
Die eingebaute LED ist die Lade-Kontrollleuchte für einen LiPo-Akku. Rot = laden, grün = laden fertig, rot-blinkend = kein Akku und dunkel = geladener Akku. Diese LED kann nicht abgeschaltet werden.
AndreasD
Hallo,
kann mir jemand helfen, wie ich die Onboard-LED abschalte? Ich weiß nicht, warum ich mich so anstelle. Bei mir blinkt sie sehr schnell. Im Sketch habe ich allerdings nichts gefunden.
Danke für eine Antwort.
Andreas
István Maszlik
Hallo! Ich kann die externen und internen Thermometer nicht anschließen. Wie richte ich es ein?
Carsten Jürges
Man könnte das noch um die Luftfeuchtigkeit (bme280) erweitern.
Weiterhin habe ich einen Balken spendiert, der anzeigt, wie alt die Messung vom Aussensensor ist. Ist diese zu alt, setze ich den Wert wieder zurück, damit dessen Anzeige unterdrückt wirdWas interessiert eine Temperatur von vor zwei Stunden …
Wenn der Wert sehr alt ist, lasse ich dieses Thermometer im WiFi sichtbar werden, damit sich das Aussenthermometer neu verbinden kann …
Mario Spies
Guten Tag,
ist es möglich das Board mit ESPEASY zu betreiben?
An welchen I/O Ports hängt das Display.
Michael Riedel
Hallo ich bin neu Hier ,
versuche seit Tagen das kleine Projekt zum laufen zu bringen und verzweifle ….
beim überprüfen bleib es hier hängen
#include
Meldung “no such file oder Directory”
wo kann ich und welche Libary " espNow " herunterladen ???
habe schon vieles versucht ohne Erfolg
beim anstecken des ESP 8266 steht auf dem Display 10 nets found
wer kann mir helfen ??
mfG Michael
Helmut Riethmeier
Warum gibt es bei den Kommentare keine Antworten zu lesen, werden die Antworten nur über Email verschickt.
Gruß Helmut
AndreasD
Hallo,
ich bin neu hier und dementsprechend nicht der Profi. Das Projekt finde ich sehr gut. Meine erste Frage ist, warum ist bei
esp_now_set_self_role(2);
standardmäßig Slave eingestellt?
Die zweite Frage: Wann nutze ich (3) Master & Slave und wann (1) Master?
Und drittens: Wenn ich einen Aussensensor mit dem ‘Master’ verbinden möchte, was trage ich dann beim Master ein, (1) oder (3)? Und wenn ich es richtig deute, dann trage ich bei dem zweiten (2) ein. Wie viele könnte ich an den Master anmelden?
Viertens: Wenn ich einen Aussensensor habe, der kein Display benötigt, kann ich dann auch einen esp8266 ESP01S WLAN nutzen? Was müsste dann im Code geändert werden?
Ich bin dankbar für jeden Hinweis.
Beste Grüße, Andreas
Thomas
Hallo.
Super Projekt. Ich hätte allerdings 2 Fragen.
1. Was stellt die Schaltung im ersten Bild dar? Die mit dem 10 kOhm Widerstand?
2. Warum ein Temperaturoffset von 15? Wozu ist das Offset gut?
Ich habe das Offset auf 0 gestellt, nun zeigt mir das Thermometer die richtige Temperatur an.
Vielen Dank.
Grüße, Thomas
Gerald
Ein 1200mAh Akku hält ohne Aufladung ca. 1 Tag.
Der 4.7 kOhm Widerstand ist nicht nötig wenn man den Datenpin mit pinMode auf INPUT_PULLUP setze.
Für einen Temperatursensor der dei Daten mit WiFi und mit Batterie betrieben werden kann, möchte ich auf den nächsten Beitrag in diesem Blog verweisen.
Sören
Meines Erachtens fehlt zwischen Plus-Pol und Daten-Pin ein 4,7kOhm Widerstand – oder ist der bei 3.3V nicht nötig?
Ich arbeite grundsätzlich mit 5V.
Passende Widerstände sollte az-delivery auch anbieten…
Stephan
Hallo Manuel,
du könntest die Temperaturen mit MQTT versenden. Für OpenHab gibt es da dann entsprechende Unterstützung.
Nutze ich auch für diverse Sensoren. Z.B.: https://github.com/stritti/smart-swimming-pool
Ralph
Das mit der Batterie würde mich auch interessieren.
Zu. Kühlschrank, der ist ein relativ guter Farradayscher Käfig mit Wifi innen ist da nicht viel. Funfakt deswegen hatte Snowden als die Journalisten ihn in HongKong aufsuchten, deren Smartphones in den Kühlschrank gesteckt.
Manuel
Hi,
interessante Sache. Wie lange würde die Batterie in etwa halten? Und wäre das WiFi geeignet, um den Sensor im SmartHome (openHAB) zu integrieren? Suche noch eine Lösung um die Kühlschranktemperatur zu überwachen.
Danke für Kommentar.
Grüße
Manuel