DS18B20 reads -127 or 85 degrees: pull-up and wiring fixes

-127 means the sensor is not answering, and 85 is the power-on value before a real reading. Check the pull-up resistor and wiring first.

What the message means

The DS18B20 uses a one-wire data line that needs a pull-up resistor to the supply. Libraries return -127 when no device responds. The sensor outputs 85 C until a conversion finishes.

Fix it in this order

  1. Fit a 4.7 kohm resistor between the data line and 3.3 V or 5 V.
  2. Check the three wires: ground, data and supply. Swapped ground and supply can damage the sensor.
  3. Use the correct pin number in the sketch and the OneWire and DallasTemperature libraries.
  4. Request the temperature after the conversion finishes. Call requestTemperatures() and read afterwards.
  5. Shorten long wires or use a lower pull-up value for long runs.
  6. Try a second sensor. Counterfeit parts are common.

Why it happens

The two numbers come from different places. The DallasTemperature library defines DEVICE_DISCONNECTED_C as -127 and returns it when it cannot get a valid reply. That covers a missing sensor, and a forum thread also reports it when the checksum on the sensor’s reply is bad, so noise on the line can produce it too.

The 85 comes from the sensor. Its datasheet gives +85 C as the value the temperature register holds after power-on, so you see 85 if you read before a conversion has finished or after the sensor has reset. Because 85 is also a real temperature, a program cannot simply reject it, so request a new reading and wait for it to complete. Compare the result with the library’s constant exactly, since a loose range check can let -127 through as a stale value.

If you see this, do this

You seeDo this
-127 alwaysNo response: pull-up, wiring or pin.
85 sometimesYou read before the conversion finished.

I2C device not found, resistor calculators.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

The DS18B20 shares one wire for power-up detection and data. Master and sensor take turns pulling the line low, and the resistor to the supply pulls it high again. Without a pull-up of about 4.7 k the line cannot return high, no sensor reply is seen and the library reports -127, its constant for a disconnected device.

The value 85 is different. A conversion takes time, up to 750 ms at 12-bit resolution and about 94 ms at 9-bit. The sensor’s temperature register holds +85 degrees C after power-up, so if you read before the conversion is done, or after a reset, you get 85 instead of a real value.

How to confirm the cause

  • Check the connections with the flat side of the TO-92 package facing you: ground on the left, data in the middle, supply on the right.
  • Measure the voltage on the data line with the sensor connected and idle. It should sit at the supply level; if it is near zero, the pull-up is missing or a short exists.
  • Count the devices found with getDeviceCount(). Zero means a wiring or pin fault.
  • Try a longer delay between the request and the read, or use the blocking mode of the library.
  • Swap in a different sensor and a short wire to rule out damage or noise.

Worked example

A reading loop that tells the failure cases apart:

#include <OneWire.h>
#include <DallasTemperature.h>

OneWire ow(4);
DallasTemperature sensors(&ow);

void setup() { Serial.begin(115200); sensors.begin(); }

void loop() {
  sensors.requestTemperatures();
  float t = sensors.getTempCByIndex(0);
  if (t == DEVICE_DISCONNECTED_C) Serial.println("no sensor");
  else Serial.println(t);
  delay(1000);
}

Common mistakes

  • Connecting the sensor with ground and supply reversed. It heats quickly and can be damaged.
  • Reading the value in the same instant as the request, without waiting.
  • Using a pull-up that is too large for a long cable.
  • Using the wrong pin number for the OneWire object.
  • Filtering out 85 and thinking the problem is solved; the cause is the timing.

If this did not fix it

  • Power in parasite mode with a weak pull-up, which fails when the sensor draws current during conversion.
  • Noise on a long cable; shorten it or use a smaller pull-up within the limits of your controller.
  • A counterfeit sensor that behaves differently from the datasheet.