DS18B20 is only giving -127

Hello to everyone,
i am trying to use an DS18B20 to get an temperature measurment.
But i only get an -127 reading.
Through the Forum i learned that this is probably an connection problem.

Is there a problem with the used librarys or is it possible that i fried the sensor?
Or something entirely different...?

Following is my used Code and the curcuit.

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

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

void setup(void)
  Serial.println("Dallas Temperature IC Control Library Demo");


void loop(void)
  Serial.print("Requesting temperatures...");
  Serial.print("Temperature for the device 1 (index 0) is: ");

I also tried an scanner which was posted from @el-supremo.

But with this i only get:

That's it.

Thanks for your Help in advance...

Please excuse me if i implemented something wrong. I am only at the beginning with the Arduino and have a lot to learn.

Hi @scout01 ,
Does your module have the resistor between +VCC and the data line?
If not, put a 4K7 resistor.
Post a link with your DS18B20 module.
RV mineirin

unfortunately i can only assume at this point.
On the board is a little component which reads 472 with an R1 next to it. This could be the resistor.

The module alone has no link, i got it out of the Sensor Kit from Elegoo.

This is the link to the provided pdf which came with the set.
Which i followed to set up and programm it.

This is the Module itself.

Thanks for your help!

Hi @scout01 .
First make sure your jumpers are good and that they are wired as per your schematic.
If you have a multimeter, measure the resistance between the OUTPUT pin and the +VCC and see if you find the value equal to or less than 4K7.
If not, then for testing connect a 4K7 resistor between arduino pin 2 and +VCC of arduino.
RV mineirin

@scout01, your topic has been moved to a more suitable location on the forum. Installation and troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category

-127 simply means "not connected", i.e. bad wiring. The resistor you allude to can hardly be anything other than the 4.7k required and, unless you have abused it, should be just fine.

I have checked my cables and also changed them out to eleminate this posibility.
I only have a pretty cheap old multimeter that couldn't really get an exact reading.
I will try to lend one which is better.

@Nick_Pyner in which way do you mean that i could have abused it?

Another concern of mine is the code.
My lecturer from University said that there could be something wrong with the librarys.
But because the code came with the module, i didn't consider it to be the problem.

You probably should have some sort of delay in your loop. Try delay(5000); for starters.


Thanks Don for your Tip.
I implemented it into my code but it still is sending the -127.

Later i meet with someone who can hopefully give me some insight.
I will post the result of this meeting.

You could have wired the module the wrong way round. The sensor itself is very robust.

You are using the right libraries. The code seems kosher. Put the delay at the beginning of the loop.

I disagree. It might just as well be a current limiting resistor for the smd LED that's right beside it.

@scout01, get a digital multimeter and measure the resistance between pins 2 & 3 on your module (while it's not connected to anything else). If you get a reading that's higher than 4700Ohms or even an out of range value ('infinite' resistance), you need to add a pullup resistor.

Try the following sketch:

//12-bit default resolution; external power supply
OneWire ds(2);
byte addr[8];         //to hold 64-bit ROM Codes of DS1
byte data[9];        //buffer to hold data coming from DS18B20
float celsius;

void setup() 
  ds.search(addr);  //collect 64-bit ROM code from sensor

void loop()

void probe()
 ds.reset();       //bring 1-Wire into idle state
 ds.select(addr); //slect with DS-1 with address addr1
 ds.write(0x44);    //conversion command
 delay(1000);   //data ready withinh DS18B20 or poll status word
 ds.select(addr);  //selectimg the desired DS18B20
 ds.write(0xBE);    //Function command to read Scratchpad Memory (9Byte)
 ds.read_bytes(data, 9); //data comes from DS and are saved into buffer data[8]
  int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
  celsius = (float)raw / 16.0;  //12-bit resolution

Thanks for all your help and suggestions.
Turns out that the module itself does need the extra pullup resistor.
The existing resistor really is only for the LED above it.

But also i got the oppurtunity to test my code and setup with another module like mine and as i suspected my sensor is simply dead. Probaly from the factory itself because another sensor from the set also turned out to be defect.

With the new sensor my code worked perfectly and immediately sends data.
That means the -127 also could mean that the sensor is broken.

Again thanks for all your help.
Have a good one!

Its common with multidrop busses like the OneWire bus to not include termination or pullup resistors in every module, since termination resistors should only be at the ends of a bus, and there should only be one pullup resistor so that its value is correct - having 12 modules on the same bus each with a 4k7 resistor would give 391 ohms, far too low...

God yes, I should have seen that. .... The idea of having a pullup for every sensor is stupid and should never happen. I guess I was suckered by the resistor value. And what's a LED doing there anyway?

The LED is there to tell if the Sensor is working.
When the code runs it blinks slowly.
But it is really not important.

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