Fix DS18B20 reading -127 °C (or stuck at 85 °C)
-127 means the sensor was not found on the 1-Wire bus; 85 means it was read before a conversion finished. Usually the 4.7 kΩ pull-up or wiring.
Community draft — report a mistake
What you see
Requesting temperatures... DONE
Temperature: -127.00 C
Requesting temperatures... DONE
Temperature: -127.00 CRequesting temperatures... DONE Temperature: -127.00 C Requesting temperatures... DONE Temperature: -127.00 C
The DS18B20 uses the 1-Wire bus: one data line that the sensor pulls low to talk. That only works with a pull-up resistor holding the line high. -127 almost always means that resistor or a wire is missing.
Quick fix — try in order
- 1
Add a 4.7 kΩ pull-up
Connect 4.7 kΩ between the DATA (yellow) wire and VCC. Without it the 1-Wire bus never goes HIGH.
- 2
Check the wire colours
Waterproof probes: red = VCC, black = GND, yellow (or white) = DATA. Some cheap probes swap colours — check with a multimeter.
- 3
Do not use parasite power for long cables
Power VCC from 3.3 V (ESP32) or 5 V (Uno) instead of tying it to GND.
- 4
Count devices first
Print sensors.getDeviceCount(). 0 means a wiring or pull-up problem, not a code problem.
- 5
Getting 85 °C? Wait for the conversion
Call requestTemperatures() and allow up to 750 ms (12-bit) before reading, or keep the library’s default blocking mode.
Why it happens
What does -127 mean?
It is DEVICE_DISCONNECTED_C in the DallasTemperature library: the sensor did not answer on the bus.
What does 85 mean?
85 °C is the DS18B20’s power-on value. Reading it means the conversion did not run or the sensor reset (often a power problem).
Long cables
Over several metres the pull-up may need to be lower (2.2 kΩ) and the cable should be twisted pair.
Board-specific notes
ESP32: Use a normal GPIO like 4 or 15 — avoid input-only pins 34–39, which cannot drive the bus.
Parts: DS18B20 — pinout, voltage and library notes.
Did this fix it?
Thanks — that helps us keep this page right.