DS18B20 Issue

Hello, I just bought the DS18B20, connected it to Arduino, copied the programs from couple of websites, but the Serial Monitor just keeps reading -127°C. What’s happening?

Do you have a 4.7k pullup resistor on the data line?
Have you wired it for parasite power or not?

Pete

el_supremo:
Do you have a 4.7k pullup resistor on the data line?
Have you wired it for parasite power or not?

Pete

Yes, pullup is in place. Im sorry but whats the difference betwen the parasite and not parasite? :smiley:

See page 7 of the datasheet

Pete

Post the code you are using (in code tags).

Pete

Hi, Try this code: I use it all the time and I know it works…

/* YourDuino Test Program   05/21/2018
- Connect cable to Arduino Digital I/O Pin 2

***  FIX Wire.h include
terry@yourduino.com */



/*-----( Import needed libraries )-----*/
//#include <OneWire.h>    // Included within recent DallasTemperature
#include <DallasTemperature.h>

/*-----( Declare Constants )-----*/
#define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/

/*-----( Declare objects )-----*/
/* Set up a oneWire instance to communicate with any OneWire device*/
OneWire ourWire(ONE_WIRE_BUS);

/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature sensors(&ourWire);

/*-----( Declare Variables )-----*/


void setup() /*----( SETUP: RUNS ONCE )----*/
{
/*-(start serial port to see results )-*/
delay(1000);
Serial.begin(9600);
Serial.println("YourDuino.com: Temperature Sensor Test Program");
Serial.println("Temperature Sensor: DS18B20");
delay(1000);

/*-( Start up the DallasTemperature library )-*/
sensors.begin();
}/*--(end setup )---*/


void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
Serial.println();
Serial.print("Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");

Serial.print("Device 1 (index 0) = ");
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" Degrees C");
Serial.print("Device 1 (index 0) = ");
Serial.print(sensors.getTempFByIndex(0));
Serial.println(" Degrees F");
delay(5000);
}/* --(end main loop )-- */

/* ( THE END ) */

bimbawz:
connected it to Arduino, but the Serial Monitor just keeps reading -127°C.

The -127 suggests you didn’t, indeed, it is the standard error message for “not connected”. If the sensor gets, or got, seriously hot, you have connected it the wrong way round. If it is still doing that, it may survive.

If it isn’t, and never did, and you are using a cheapo breadboard, now is the time to check it, and any other wiring. I have never had a problem with a breadboard, but you might if you have components with thin wires.

If you don’t know what parasite power is, you are probably not using it. Not using it is a really good idea.

There is nothing to suggest there is anything wrong with the code, and the -127 suggests there is probably nothing wrong with it.

Check connections first.

Nick_Pyner:
The -127 suggests you didn't, indeed, it is the standard error message for "not connected". If the sensor gets, or got, seriously hot, you have connected it the wrong way round. If it is still doing that, it may survive.

If it isn't, and never did, and you are using a cheapo breadboard, now is the time to check it, and any other wiring. I have never had a problem with a breadboard, but you might if you have components with thin wires.

If you don't know what parasite power is, you are probably not using it. Not using it is a really good idea.

There is nothing to suggest there is anything wrong with the code, and the -127 suggests there is probably nothing wrong with it.

Check connections first.

So I checked connections, everything should be fine, but it's not working..

Have you tested the Program Codes of Post#5? I have tested these codes in the following setup and they are working well!

When someone wants to help you by providing some means; try to help him back by providing feedback.

bimbawz:
So I checked connections, everything should be fine

You say "should be fine", but it isn't, and -127 is telling you that there is no connection.

I can only assume that "no connection" can be interpreted as "nothing to read because you fried the sensor", but I can tell you for certain that the DS18B20 can survive quite a bit of frying.

Some good procedural advice is here
http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

GolamMostafa:
Have you tested the Program Codes of Post#5? I have tested these codes in the following setup and they are working well!

When someone wants to help you by providing some means; try to help him back by providing feedback.

I tried all these codes, but it's not working..

I tried all these codes, but it's not working..

Try by changing the sensor.

There’s a lot of fakes going around now, a simple transistor RELABELED as a DS18B20, where did you buy it?

For a “real” DS18B20, DMM set to “Diode Test”

Meter probes
BLK RED

PIN PIN Reading
2 1 0.495V
3 1 0.555V
All other combinations = “OL”
DS18B20_pinout.png

outsider:
a lot of fakes going around now,

God, I never thought of that. I couldn't see what could be wrong here.

Thanks for help everyone, I somehow checked the connections and it works! Serial Monitor output is stable temperature, pretty close to the real temps in my room. Thanks for help :slight_smile:

bimbawz:
Thanks for help everyone, I somehow checked the connections and it works!

Sounds like typical breadboard connection problems. Always have to check that first when using a solderless breadboard.