Measuring temperature with the DS18B20

FunduinoPublished on

Temperatur messen mit vier verschiedenen Boards

Der DS18B20 ist ein digitaler Temperatursensor. Er liefert den Messwert bereits als fertige Zahl in Grad Celsius, du musst also nichts umrechnen. Es gibt ihn in zwei Bauformen: als bedrahtete Variante fürs Steckbrett und als wasserdichte Ausführung mit Edelstahlhülse am Kabel.

Diese Anleitung zeigt dir den Anschluss an vier verschiedenen Boards:

  • Arduino UNO
  • Wemos D1 Mini
  • ESP32
  • NodeMCU

Für alle Boards gilt: Der Sensor braucht zwischen Datenleitung und 5V einen Pull-up-Widerstand von 4,7 kΩ. Bei den fertigen Modulen mit Platine ist dieser bereits verbaut, bei der bedrahteten Variante musst du ihn selbst setzen.

DS18B20 temperature sensor with XH2.54-3P socket
The DS18B20 with socket

You need this

DS18B20 temperature sensor - digital, -55 to +125 °C, XH2.54 socket DS18B20 temperature sensor - digital, -55 to +125 °C, XH2.54 socket 4,85 € *Item no. F23109069About the product — DS18B20 temperature sensor - digital, -55 to +125 °C, XH2.54 socket
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm

All 3 parts together 17,71 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Choose a microcontroller

Pins, schematic, and sketch in the steps change with your selection. It remains saved.

The hardware

Measuring temperature with sensors is an important standard application for microcontrollers.

The DS18B20 requires only a single data line in addition to the Ground (GND) and 3.3 V or 5 V connections. It is available in two versions: as a module with an XH2.54-3P socket and as a wired version in a waterproof stainless steel housing.

DS18B20 temperature sensor with XH2.54-3P socket
The DS18B20 with socket
Wired DS18B20 temperature sensor in a stainless steel housing
The wired version
1 / 2

The schematics for four boards

The sensor can be used with all four boards. These guides explain how to set up each board in the Arduino IDE:

Schematic: DS18B20 with Arduino UNO
Arduino UNO
Circuit diagram: DS18B20 on the Wemos D1 Mini
Wemos D1 Mini
Wiring diagram: DS18B20 on the ESP32-Wroom
ESP32-Wroom
Circuit diagram: DS18B20 on NodeMCU
NodeMCU
1 / 4

Install the required library

For the DS18B20, you need the DallasTemperature library. It also requires the OneWire library.

DallasTemperature library in the library manager
The DallasTemperature library

Display measurement data in the Serial Plotter

You can find the Serial Plotter in the Arduino IDE under Tools → Serial Plotter. It displays the measured values as a curve instead of just listing them as numbers.

Temperature curve in the Arduino IDE Serial Plotter
Measurement data in the Serial Plotter
Tools menu with the Serial Plotter item
Tools → Serial Plotter
1 / 2

Display measurement data on an OLED

Instead of sending the values to the computer, you can display them directly on an OLED display. To do this, you also need the Adafruit SSD1306 library. The circuit diagrams are available again for all four boards.

The sketches for this guide are still missing.

DS18B20 reading on an OLED display
Measurement data on an OLED
Adafruit SSD1306 Library in Library Manager
The Adafruit SSD1306 library
Circuit diagram: DS18B20 and OLED with Arduino UNO
Arduino UNO with OLED
Circuit diagram: DS18B20 and OLED on the Wemos D1 Mini
Wemos D1 Mini with OLED
Circuit diagram: DS18B20 and OLED with ESP32-WROOM
ESP32-Wroom with OLED
Wiring diagram: DS18B20 and OLED on the NodeMCU
NodeMCU with OLED
1 / 6
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.