The DS18B20 is a digital temperature sensor in a waterproof probe housing with a 1 m cable. It communicates over the 1-Wire interface and is commonly used for measuring liquids, outdoor air, or other environments where the sensor needs protection from moisture.
| Pin | Signal | Description |
|---|---|---|
VDD |
power | Positive supply for the DS18B20 probe, typically 3.0–5.5 V. |
DQ |
data | 1-Wire digital data line; requires a pull-up resistor to VDD. |
GND |
ground | Ground return for the DS18B20 temperature probe. |
| From | To | Wire |
|---|---|---|
board:5V |
x1:VDD |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:DQ |
green |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t ONE_WIRE_BUS = 2;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
sensors.begin();
Serial.println("DS18B20 temperature sensor example");
}
void loop() {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
if (temperatureC == DEVICE_DISCONNECTED_C) {
Serial.println("Sensor not found or disconnected");
} else {
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" C");
}
delay(1000);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free