DS18B20 Temperature Sensor -127 Problem

Hello everyone,

I have a problem with running a DS18B20 Temperature Sensor with Arduino Uno. I have followed the instructions, set up, and code mentioned here: Guide for DS18B20 Temperature Sensor with Arduino

However, it always shows "Celsius temperature: -127.00 - Fahrenheit temperature: -196.60" . I have tried an ESP32 and still have the same problem. I have also switched from normal to parasite mode. The values do not change when I heat the sensor with my hand.

Can anyone help me with solving this problem? :slight_smile:

Please show a schematic of the circuit of your setup and include a clear photograph of the system as you've built it. Please also share the code you're using to read out the sensor.

-127 means the reading went wrong. Could be cables' quality, power, other parts of the circuit or possibly the code


/*********
  Rui Santos
  Complete project details at http://randomnerdtutorials.com  
  Based on the Dallas Temperature Library example
*********/

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

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 7

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // Start serial communication for debugging purposes
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
}

void loop(void){ 
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  
  Serial.print("Celsius temperature: ");
  // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  Serial.print(sensors.getTempCByIndex(0)); 
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0));
  delay(1000);
}

Looks like you've got both VCC and GND of the sensor connected to GND on the breadboard. Try powering the sensor with 5V, and verify you've correctly interpreted the wire colors of your sensor.

Now it works! Thank you guys :slight_smile:

1 Like

Great to hear!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.