The DS18B20 is the go-to probe for water tanks, aquariums, compost and cold storage — it comes sealed in a steel tube on a 1 m cable. On a Nano it needs one data pin and one resistor.
Wire the probe’s three cores to 5V, D2 and GND, and put a 4.7 kΩ resistor between D2 and 5V. The sketch counts the probes it finds at startup and prints each one every second.
Wiring
| Arduino Nano | DS18B20 (1-Wire) | Wire | Notes |
|---|---|---|---|
| 5V | VDD | red | Probe cable: red = VDD. |
| D2 | DQ | yellow | Probe cable: yellow (sometimes white) = DQ. |
| 5V | DQ | red | Via 4.7 kΩ — One pull-up for the whole bus, however many probes. |
| GND | GND | black | Probe cable: black = GND. |
3.0–5.5 V part, 5 V board. Power it from your board's logic voltage (3.3 V on ESP32/Pico, 5 V on Uno) so DQ never goes above the GPIO limit. DQ needs a 4.7 kΩ pull-up to that same supply.
Board quirks
- Several probes can share D2, VDD and GND. Each has a unique 64-bit address; the sketch reads them by index.
- At 5 V on a Nano, cable runs of 10–20 m work with a 4.7 kΩ pull-up. For longer runs, drop to 2.2 kΩ and use twisted-pair cable.
- Use “normal” power (VDD to 5V), not parasite mode, for waterproof probes in water tanks or soil — it is much more reliable.
- A 12-bit reading takes ~750 ms. The Nano blocks during
requestTemperatures(); callsensors.setWaitForConversion(false)if you need the loop free.
Code
// DS18B20 waterproof temperature probes on an Arduino Nano — reads every probe on the bus.
// VDD → 5V, DQ → D2 with a 4.7 kΩ pull-up to 5V, GND → GND. Several probes can share D2.
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t ONE_WIRE_PIN = 2;
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
sensors.setResolution(12);
Serial.print(F("Probes found: "));
Serial.println(sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures(); // a 12-bit conversion takes about 750 ms
uint8_t n = sensors.getDeviceCount();
for (uint8_t i = 0; i < n; i++) {
float c = sensors.getTempCByIndex(i);
Serial.print(F("Probe "));
Serial.print(i);
Serial.print(F(": "));
if (c == DEVICE_DISCONNECTED_C) {
Serial.println(F("disconnected (-127)"));
} else {
Serial.print(c, 2);
Serial.println(F(" C"));
}
}
if (n == 0) Serial.println(F("No probe found - check the 4.7k pull-up"));
delay(1000);
}// DS18B20 waterproof temperature probes on an Arduino Nano — reads every probe on the bus.
// VDD → 5V, DQ → D2 with a 4.7 kΩ pull-up to 5V, GND → GND. Several probes can share D2.
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t ONE_WIRE_PIN = 2;
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
sensors.setResolution(12);
Serial.print(F("Probes found: "));
Serial.println(sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures(); // a 12-bit conversion takes about 750 ms
uint8_t n = sensors.getDeviceCount();
for (uint8_t i = 0; i < n; i++) {
float c = sensors.getTempCByIndex(i);
Serial.print(F("Probe "));
Serial.print(i);
Serial.print(F(": "));
if (c == DEVICE_DISCONNECTED_C) {
Serial.println(F("disconnected (-127)"));
} else {
Serial.print(c, 2);
Serial.println(F(" C"));
}
}
if (n == 0) Serial.println(F("No probe found - check the 4.7k pull-up"));
delay(1000);
}Library: DallasTemperature (Miles Burton (also install OneWire by Jim Studt / Paul Stoffregen)) — compiled with OneWire 2.3.8.
Expected serial output
Probes found: 2
Probe 0: 28.81 C
Probe 1: 24.06 CProbes found: 2 Probe 0: 28.81 C Probe 1: 24.06 C
Common errors
Reads -127 °C
Missing pull-up, wrong pin, or a broken probe wire. Full fix.
Reads exactly 85 °C
85 °C is the power-on value: the reading was taken before a conversion finished, or VDD browned out. Check the 5V wire.