Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

DS18B20 with Arduino Nano — one or many probes on D2

Wire one or more waterproof DS18B20 probes to an Arduino Nano on D2 with a 4.7 kΩ pull-up and print every probe’s temperature every second.

Arduino C++Verified — core avr 1.8.8, OneWire 2.3.8, 3 Nov 2026Compile-only

Community draft — report a mistake

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 NanoOnly the pins used are shown · 5 V logicDS18B20 (1-Wire)4.7k → 5V5VGNDD2GNDDQVDD
Also needed: 4.7 kΩ resistor.
Every connection
Arduino NanoDS18B20 (1-Wire)WireNotes
5VVDDredProbe cable: red = VDD.
D2DQyellowProbe cable: yellow (sometimes white) = DQ.
5VDQredVia 4.7 kΩ — One pull-up for the whole bus, however many probes.
GNDGNDblackProbe 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(); call sensors.setWaitForConversion(false) if you need the loop free.

Code

ds18b20-nano.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// 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

Serial Monitor · 115200Output
Probes 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.

↑↓ to move · Enter to open