The DS18B20 digital thermometer offers 9-bit to 12-bit Celsius temperature readings and features an alarm function with nonvolatile, user-programmable upper and lower trigger points. It communicates via a 1-Wire bus that requires only one data line (and ground) to connect with a central microprocessor. Additionally, the DS18B20 can draw power directly from the data line, known as "parasite power", eliminating the need for an external power supply.
Each DS18B20 has a unique 64-bit serial code, enabling multiple units to operate on the same 1-Wire bus. This makes it easy to control multiple DS18B20s from a single microcontroller over a large area.
This feature benefits applications such as HVAC environmental controls, temperature monitoring systems inside buildings, equipment or machinery, and process monitoring and control systems.
The BME/BMP sensors can be integrated with the Tasmota system.
For more details, see here: https://tasmota.github.io/docs/DS18x20/
If you'd like to support the development of the site with the price of a coffee — or a few — please do so here.
Here's a handy tip: you can quickly save this page as a PDF by clicking “export to PDF” in the menu on the right side of the screen.
Each 1-Wire device has a unique 64-bit 'ROM' address, which includes an 8-bit family code, a 48-bit serial number, and an 8-bit CRC. The CRC helps verify data integrity.
For example, the sample code below checks if the device being addressed is a DS18S20 temperature sensor by looking for its family code, 0x10. To use the sample code with the newer DS18B20 sensor, you would look for a family code of 0x28. For the DS1822, you would check for 0x22.
The DS18B20 is a popular 1-Wire digital temperature sensor known for its simplicity and the ability to connect multiple sensors to a single Arduino pin.
Wiring & Pull-up Resistor
The most critical component of the setup is the 4.7 kΩ pull-up resistor. Without it, the 1-Wire bus cannot return to a “high” state, and you will not get any readings.
Required Libraries
To run the code below, install these two libraries via the Arduino Library Manager (Sketch > Include Library > Manage Libraries):
Arduino Sketch
This script initializes the sensor and prints the temperature in both Celsius and Fahrenheit every second.
#include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); Serial.println("DS18B20 Single Sensor Read"); // Start up the library sensors.begin(); } void loop(void) { // Send the command to get temperatures Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); Serial.println("DONE"); // Use index 0 to refer to the first (and only) sensor on the wire float tempC = sensors.getTempCByIndex(0); // Check if reading was successful if(tempC != DEVICE_DISCONNECTED_C) { Serial.print("Temperature: "); Serial.print(tempC); Serial.print("°C | "); Serial.print(DallasTemperature::toFahrenheit(tempC)); Serial.println("°F"); } else { Serial.println("Error: Could not read temperature data"); } delay(1000); }
| Page | Date | Tags |
|---|---|---|
| 2026/04/23 21:51 | 1-wire, communication, bus, microlan, i2c, uart, usart, ds18b20 | |
| 2026/04/23 21:51 | 1-wire, communication, bus, xml, iec 61850, iec, ethernet, scl, goose, ied | |
| 2026/04/23 21:52 | dht11, dht20, dht22, temperature, humidity, pressure, sensor, 1-wire, arduino, code | |
| 2026/04/23 21:52 | ds18b20, sensor, 1-wire, communication, arduino, thermometer, parasitic mode |
This page has been accessed for: Today: 1, Until now: 10