ds18b20 sensor send a -127 °C value when temperature is lower than -20° C


i´m using a ds18b20 sensor to sense temp in a freezer. but when temp is lower than -20, the value is -127. what´s happening?

the next is the serial monitor:

-19.87 ° C
-20.00 ° C
-20.06 ° C
-20.12 ° C
-20.25 ° C
-20.31 ° C
-127.00 ° C
-127.00 ° C
-127.00 ° C

that´s the code:

include <OneWire.h> //Se importan las librerías
#include <DallasTemperature.h>
#define Pin 2 //Se declara el pin donde se conectará la DATA
OneWire ourWire(Pin); //Se establece el pin declarado como bus para la comunicación OneWire
DallasTemperature sensors(&ourWire); //Se instancia la librería DallasTemperature
void setup() {
sensors.begin(); //Se inician los sensores
void loop() {
sensors.requestTemperatures(); //Prepara el sensor para la lectura
Serial.print(sensors.getTempCByIndex(0)); //Se lee e imprime la temperatura en grados Celsius
Serial.println(" grados Centigrados");

delay(10000); //Se provoca un lapso de 1 segundo antes de la próxima lectura

thanks in advance

Is the Arduino outside the freezer ? The DS18B20 should work down to -55 degrees Celsius according to the datasheet.

Do you use the newest OneWire and DallasTemperature libraries ? Could you add extra checks ? For example the isConnected() and others. The example in the OneWire library shows all the binary data with checksum.

According to DallasTemperature.h : https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/master/DallasTemperature.h the value of -127 means : DEVICE_DISCONNECTED_C You have lost the connection to the sensor. Does it happen always at exactly the same temperature ?

thanks for reply.
the problem was that the gnd cable was broken.

O, so it was not a bug in the library, but the library actually told what was wrong :P I'm glad you found the problem so quick.