A DS18B20 -127 °C reading is not a temperature at all: -127 is the error value the DallasTemperature library returns when the sensor did not answer or sent corrupted data. A steady 85 °C is different. It is the value the sensor holds in its temperature register at power-up, so you are reading it before a conversion has finished, or the sensor is resetting mid-conversion.
So the two numbers point to two different families of faults. -127 means communication: wiring, the pull-up resistor, the GPIO, the cable. 85 means timing or power: the conversion never completed. Keep that split in mind and the fix is usually quick.
Quick Fix — Try This First
- Check the pinout: on the TO-92 package seen from the bottom, pin 1 is GND, pin 2 is DQ (data) and pin 3 is VDD.
- Fit a 4.7 kΩ resistor between DQ and VDD, close to the microcontroller.
- Power VDD from the same rail as the pull-up: 3.3 V on an ESP32, 3.3 V or 5 V on an Arduino Uno.
- Run the sensor count sketch in step 3; it must report at least 1 device.
- If you see 85 °C, make sure
requestTemperatures()runs before every read and that you wait 750 ms at 12-bit resolution.
Check: the serial monitor shows a plausible room temperature that changes when you pinch the sensor.
What the DS18B20 -127 and 85 values really mean
The DS18B20 stores each result in a 16-bit register. Its datasheet gives the power-on reset value of that register as 0550h, which is +85 °C. Nothing is measured until the microcontroller sends a Convert T command, so any read taken before the first conversion ends returns exactly 85.0.
The -127 comes from software. In DallasTemperature 4.0.5, DEVICE_DISCONNECTED_C is defined as -127. The library returns it when the bus reset sees no presence pulse, when the 9-byte scratchpad comes back as all zeros, or when its CRC does not match. getTempCByIndex() also returns -127 when no sensor exists at that index.
Recent versions of the library also recognise two bad scratchpad patterns, the power-up pattern and a reading of 07FFh that signals insufficient power. They return internal error codes for these, and getTempC() converts both to -127. That is why the same fault can show 85 on one setup and -127 on another, depending on library version.
| Value you read | Where it comes from | Fault family |
|---|---|---|
| -127 °C (-196.6 °F) | Library error value, no valid reply | Wiring, pull-up, GPIO, cable, CRC errors |
| 85 °C exactly | Register value at power-up (0550h) | No conversion requested, read too early, sensor reset |
| 127.94 °C | Register reads 07FFh | Sensor starved of power; recent library versions flag it as insufficient power |
| Plausible but jumps by whole degrees now and then | Occasional bit errors | Long cable, weak pull-up, noise |
Symptoms
A wiring fault usually gives -127 from the first read. If the sensor reads correctly for minutes and then drops to -127 for one or two samples, suspect the cable or a marginal pull-up rather than the code.
The 85 °C symptom tends to appear on the very first reading after boot, or on every reading when the sketch reads the temperature without requesting a new conversion. With parasite power it can also appear at random, because the sensor browns out during the conversion and restarts with 85 in its register.
Diagnosis table
| Symptom | Likely cause | Next action |
|---|---|---|
| -127 on every read, device count 0 | Wrong pin order, missing pull-up, wrong GPIO number | Steps 1 to 3 |
| -127 on every read, device count 1 | Reading by the wrong index or address, or CRC errors | Step 3, then step 6 |
| 85 on the first read only | First read before any conversion | Step 4 |
| 85 on every read | No requestTemperatures(), or non-blocking mode without a wait | Step 4 |
| Random 85 or -127 with VDD grounded | Parasite power without a strong pull-up | Step 5 |
| Works on the bench, fails with the long probe | Cable capacitance or pull-up too weak | Long cables |
Step-by-step fix
1. Confirm the pinout and supply
Hold the TO-92 sensor with the flat face toward you and the legs pointing down: from left to right you have GND, DQ, VDD. The datasheet draws the same order from the bottom view as pins 1, 2 and 3. The supply range is 3.0 V to 5.5 V in local power mode.

Waterproof probes hide the sensor in a steel tube, and their wire colours are chosen by the probe maker, not by the datasheet. Use the seller's diagram, or check which wire reaches which pin if the probe has a visible solder joint.
Check: with the board powered, VDD to GND reads 3.3 V or 5 V at the sensor's legs. If it didn't work: follow the supply wire back to the board; a breadboard rail split in the middle is a classic trap.
2. Fit and measure the pull-up
DQ is an open-drain line: the sensor can only pull it low, so something must pull it high. The datasheet circuits use 4.7 kΩ between DQ and the pull-up supply. Without it, the line floats and the library gets no presence pulse, hence -127.
Measure DQ to GND with the sketch idle. You should read the supply voltage, or within a few tenths of a volt of it. A reading near 0 V means DQ is shorted or the resistor goes to the wrong rail.
On an ESP32, tie the pull-up to 3.3 V, never to 5 V: the ESP32's GPIOs are 3.3 V pins. On an ESP32, also avoid GPIO 34 to 39. Espressif documents them as input-only, so they cannot drive the 1-Wire line low and the sensor never answers.
Check: DQ idles at the supply voltage. If it didn't work: remove the sensor and measure again; if DQ now reads correctly, the sensor or its cable is shorting the line.
3. Count the sensors on the bus
This sketch tells you whether the library can see anything at all, and whether the sensor is wired for parasite power. Change the 4 to your GPIO number.

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(4); // DQ on GPIO 4
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
Serial.print("Sensors found: ");
Serial.println(sensors.getDeviceCount());
Serial.print("Parasite power: ");
Serial.println(sensors.isParasitePowerMode() ? "yes" : "no");
}
void loop() {}
Expected result: Sensors found: 1 for one sensor, and "Parasite power: no" when VDD is wired to the supply.
Check: the count matches the number of sensors you connected. If it didn't work: a count of 0 sends you back to steps 1 and 2; also confirm the GPIO number matches the pin label on your board, since many ESP32 boards print GPIO numbers while Arduino-style pins use D-labels.
4. Fix the 85 °C reading with proper timing
Every reading needs two calls: requestTemperatures() starts the conversion, then getTempCByIndex(0) reads the result. By default the library blocks until the conversion is done, so this order is enough.
If your code calls setWaitForConversion(false) to avoid blocking, you must wait yourself. The datasheet gives the maximum conversion time per resolution:
| Resolution | Step size | Max conversion time |
|---|---|---|
| 9-bit | 0.5 °C | 93.75 ms |
| 10-bit | 0.25 °C | 187.5 ms |
| 11-bit | 0.125 °C | 375 ms |
| 12-bit (default) | 0.0625 °C | 750 ms |
Worked example: a sketch that starts a conversion and reads 200 ms later works at 10-bit (187.5 ms) but returns stale data or 85 at the default 12-bit, which needs up to 750 ms. Either wait 750 ms or set the resolution with sensors.setResolution(10).
Check: the first value after boot is no longer 85. If it didn't work: if 85 still appears at random times, the sensor is resetting during the conversion; go to step 5.
5. Rule out parasite power problems
In parasite power mode, VDD is grounded and the sensor draws its power from DQ. The datasheet says the current can reach 1.5 mA during a conversion, more than a 4.7 kΩ resistor can deliver while keeping the line high. It calls for a strong pull-up, typically a MOSFET that ties DQ straight to the rail within 10 µs of the Convert T command and for the whole conversion.
Without that strong pull-up, the sensor browns out, restarts, and you read 85 or -127. The simplest fix is to wire VDD to the supply and use three wires. The datasheet also advises against parasite power above +100 °C (212 °F), because leakage currents rise.
Check: the step 3 sketch now reports "Parasite power: no" and the random values stop. If it didn't work: if you must keep two wires, add the MOSFET strong pull-up from the datasheet's Figure 4, or switch to a 1-Wire driver chip.
6. Add a retry instead of trusting one bad sample
A single CRC error on a long or noisy line should not end up in your data. This function retries three times and returns NAN when every attempt fails.
float readTempC(uint8_t tries = 3) {
for (uint8_t i = 0; i < tries; i++) {
sensors.requestTemperatures(); // blocks until done
float t = sensors.getTempCByIndex(0);
if (t != DEVICE_DISCONNECTED_C && t != 85.0) return t;
delay(100);
}
return NAN;
}
Rejecting 85.0 also rejects a real 85 °C. If your process can reach that temperature, accept 85 when the previous valid reading was already above, say, 80 °C.
Check: your log shows NAN only when you unplug the sensor. If it didn't work: if failures stay frequent, the bus itself is marginal; see the next section.
7. Confirm the reading in ice water
Once the bus is stable, check that the value is right, not just plausible. Fill a glass with crushed ice, top it up with a little water, stir, and leave the probe in the middle for a few minutes. The mixture sits at 0 °C (32 °F).

The datasheet allows ±0.5 °C between -10 °C and +85 °C, so a good sensor reads between -0.5 °C and +0.5 °C (31.1 °F to 32.9 °F) here. Note the offset of each probe if you use several.
Check: the reading settles inside that band and stays there. If it didn't work: a value far outside the band on a clean bus points to a damaged or counterfeit sensor; replace it rather than correcting it in code.
Long cables and several sensors
Cable capacitance slows the rising edge, because the pull-up resistor has to charge it. The time constant is simply R × C. With 1 nF of cable capacitance, 4.7 kΩ gives 4.7 µs; 2.2 kΩ gives 2.2 µs. The datasheet's read data valid time is 15 µs, so a slow edge eats into that window.
A lower resistor speeds up the edge, but the sensor must still pull the line low. The datasheet specifies a 4.0 mA sink at 0.4 V. At 5 V, 2.2 kΩ draws 2.3 mA; at 3.3 V, 1.5 kΩ draws 2.2 mA. Both stay inside that limit. Change the resistor only after you confirm that the probe works on a short cable.
With several sensors, run the bus as one line from sensor to sensor rather than a star of separate branches, and read each one by its 64-bit address instead of by index. The index order follows the bus search, so adding a sensor can shift the indexes and make the wrong probe report -127.
Common mistakes
- Pull-up wired to 5 V while the ESP32 reads the line.
- Sensor plugged in backwards: VDD and GND swapped.
- Reading with
getTempCByIndex()without callingrequestTemperatures()first. - Non-blocking mode with a fixed 100 ms delay at 12-bit resolution.
- Two-wire probe treated as three-wire, with VDD left floating instead of grounded.
If it still fails
Three causes remain when the wiring checks out. First, a counterfeit or damaged sensor: try a second sensor on the same wiring. Second, interrupt-heavy code: 1-Wire timing is in microseconds, and a Wi-Fi or PWM interrupt landing mid-slot corrupts bits; test with a minimal sketch. Third, power: a board that browns out briefly can glitch the bus too. The ESP32 brownout guide covers how to confirm that.
If you only need a rough temperature and the DS18B20 keeps failing over a long cable, an analog sensor is a valid alternative; the NTC voltage divider with an ESP32 shows the calculation. For a bus that refuses to answer at all, the pull-up logic is close to the one in our I2C scanner troubleshooting guide.
Conclusion
- Read -127 as "no valid reply" and 85 as "no finished conversion".
- Check GND, DQ, VDD order and the 4.7 kΩ pull-up to the right rail.
- Count sensors with the test sketch before debugging your main code.
- Request a conversion and wait up to 750 ms at 12-bit before reading.
- Use three-wire power, a retry routine and address-based reads on long buses.
Frequently asked questions
Can I use a 10 kΩ pull-up instead of 4.7 kΩ?
On a few centimetres of wire it often works, but it slows the rising edge and leaves less margin. Use 4.7 kΩ as the datasheet shows, and go lower only for long cables.
Why does my sensor read 85 °C only once after a reset?
Your first read happens before the first conversion has finished. Call requestTemperatures() in setup() and discard that first result, or make sure the first read in loop() follows a completed request.
How many DS18B20 sensors can share one GPIO?
Each sensor has a unique 64-bit ROM code, so several can share one data line. The practical limit is set by cable length and load, not by addressing; test the full set at its real cable length.
Why do two DS18B20 sensors on the same bus disagree by half a degree?
Each sensor may be off by up to ±0.5 °C in the -10 °C to +85 °C range, so two good parts can differ by up to 1 °C. Record each probe’s offset in the ice-water test from step 7 and subtract it in code.
Can I connect a 5 V DS18B20 probe to an ESP32?
Yes. The sensor runs from 3.0 V, so power it at 3.3 V and pull DQ up to 3.3 V. That keeps the data line within the ESP32's voltage limit.
Sources
- Analog Devices (Maxim Integrated), DS18B20 datasheet (consulted December 4, 2026)
- DallasTemperature library, version 4.0.5 source code (consulted December 4, 2026)
- Espressif, ESP32 GPIO and RTC GPIO documentation (consulted December 4, 2026)
- Photo credits, Wikimedia Commons, cropped: Sensor DS18B20 (Leonardo Postay, CC BY-SA 4.0); USB to RS-232 to 1-Wire to DS1820 (Stephen Edmonds, CC BY-SA 2.0)
Last updated: December 4, 2026.
Be the first to leave a comment.