This one is about the wire, not the chip. Nothing below changes with the board you picked, which is why the chip and language switches are not on it. They come back on the ESP32 pages this one sits underneath.
1-Wire and device chains
Dallas 1-Wire puts a unique 64-bit serial number in every device, which turns a single data line into a bus you can hang a dozen sensors off. The wiring never changes as you add them; only the eight bytes you address them by.
Add sensors, then change the command. Watch what "whoever is out there" costs you once there is more than one of them.
The address is burned in at the factory
Every 1-Wire device carries a 64-bit ROM code: a family byte saying what kind of chip it is (0x28 for a DS18B20), six bytes of serial that are unique in the world, and a CRC byte. You cannot change it and you do not have to — no jumpers, no solder blobs, no address conflicts, ever.
That is the whole difference from the DHT on the previous page. Same one wire, same pull-up, same microsecond timing underneath. Adding an addressing scheme is what turns a sensor into a bus.
Three commands is most of it
SEARCH ROM discovers what is out there. Run it once, print the codes, write them down.
MATCH ROM sends a full 64-bit code, after which exactly one device is listening and the rest ignore everything until the next reset.
SKIP ROM means "everyone". It is a real shortcut with one device and a trap with two, because the line is open-drain: any device can pull it low and none can push it high, so two simultaneous answers are ANDed together by the wire. The master gets a clean number that nobody sent.
That is the failure worth remembering. It does not look like a failure. Two sensors at 22.5 °C and 24.1 °C, read with SKIP ROM, return 16.0 °C — a plausible temperature, logged happily for a month.
Wiring a chain
Three wires: 3V3, ground, and data with a single 4.7 kΩ pull-up to 3V3 for the whole bus, not one per sensor. Sensors go anywhere along the line — a star of long stubs is worse than a single run with short taps.
Sixty metres of ordinary cable is realistic. Beyond that, or on a noisy site, drop the pull-up to 2.2 kΩ and use one twisted pair for data and ground.
#include <OneWire.h>
#include <DallasTemperature.h>
#define BUS 4
OneWire wire(BUS);
DallasTemperature sensors(&wire);
DeviceAddress tank = { 0x28, 0x3C, 0x01, 0xD6, 0x07, 0xA5, 0xF2, 0x1B };
void setup() {
Serial.begin(115200);
sensors.begin();
Serial.printf("%d device(s)\n", sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures();
Serial.println(sensors.getTempC(tank)); // by address, not by index
delay(1000);
}getTempC(index) exists and you should not use it in anything permanent. The
index is the order the search happened to find them in, so unplugging one
sensor silently renames the others.
When to reach for it
Temperature in more than one place, metres apart, on one pin. Nothing else here competes: I2C will not go down a long cable, and SPI would want a pin per sensor. If your project is "how hot is it in six places", this is the answer.
Edit this page — content/esp32/1-wire-and-device-chains.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.