Struggling to get DS18B20 Temperature sensor working

Hi all,

As above, I've been trying for so long and struggling still and was hoping someone could please help

I've tried wiring it up in parisitic power mode, and direct. Following this:

Link here

And this for parisitic:

But in the direct power mode I just get a reading of -127 degrees and the sensor actually gets burning hot. And in parisitic mode, I still get the -127 degrees (no burning sensor though), and if I remove the sensor while in the parisitic setup, then the reading stays at -127 degrees also

Code below

Anyone able to help please? I'd really appreciate it

Thanks!

#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
 
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
}
 
 
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
 
}

Just completely tried again from scratch, this time using the 'simple' example sketch from the dallas library and parisitic mode and I get the same... -127 degrees regardless of whether the sensor is plugged in or not

I have also tried a different sensor just in case, but that doesn't seem to be the issue since the sensor isn't having any effect on the reading

Thanks

Try these three things:

  • I think the 47k resistor is too high. Try 4.7k
  • If that doesn't help, wire the DS18B20 in non-parasite mode and see if that works.
  • I think there's a OneWire scanner sketch out there somewhere. See if it can detect your DS18B20.

// 0 refers to the first IC on the wire

For an explanation of how OneWire devices are enumerated (indexed) see my first message in DS1822: How does the program assign the sensor's index? - Programming Questions - Arduino Forum

Pete

Hi Pete

Sorry I think that image has a typo in it (it is a screenshot from a video I didn't make), I am actually using a 4.7K resistor

Thanks for the other info too, I'll take a look for that scanner sketch and see what I can find out

Thanks! :slight_smile:

127 means a bad connection. I believe it may also signal inadequate power. Your diagrams says "any digital pin" but implies you are using pin 46 while your code specifically states you are using pin 2. The code you post is junk and possibly incomplete. This code might help. Strip out what you don't need

/* Basic 2xDS18B20 code for serial monitor, bluetooth, Excel or w.h.y.
Derived from Hacktronics. USE THEIR ADDRESS SNIFFER and substitute your 
numbers. Use Hacktronics connections diagram. 

http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

Stay away from using parasite power
-127C means bad connection
85 means you haven't gotten a read yet, probably just the 
wrong order of commands
*/

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

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

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

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
  
byte Thermo1[8] = {0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte Thermo2[8] = {0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
float tempC,Temp1,Temp2;  

void setup(){
  Serial.begin(9600);
  sensors.begin();
  delay(500);//Wait for newly restarted system to stabilize
  sensors.setResolution(Thermo1, 12); 
  sensors.setResolution(Thermo2, 12);
}

void loop() {
 sensors.requestTemperatures();  // call readings from the addresses
  Temp1 = sensorValue(Thermo1);
  Temp2 = sensorValue(Thermo2);  

Serial.print("      Temp1 = ");
Serial.print(Temp1);
Serial.print("      Temp2 = "); 
Serial.println(Temp2);
delay(1000);
}

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

Nick_Pyner:
127 means a bad connection. I believe it may also signal inadequate power. Your diagrams says "any digital pin" but implies you are using pin 46 while your code specifically states you are using pin 2. The code you post is junk and possibly incomplete. This code might help. Strip out what you don't need

Sorry for the rushed initial post Nick, I was in a hurry and copied that image from a video I was following, I was however using pin 2 on my Arduino Yun despite the image saying 46

Thanks for the info and code, I'll try that this evening

Out of interest, with regards to inadequate power, if that is the issue, what can be done about this?

Thanks for the help :slight_smile:

azibux1:
Arduino Yun

Out of interest, with regards to inadequate power, if that is the issue, what can be done about this?

I'm not familiar with the Yun and I'm only speculating about inadequate power, but generally, a 9v wall wart fixes all and you will be amazed how many people try to use 9v batteries or questionable USB sources. Having said that, a Yun with a DS18B20 outputting to serial monitor is unlikely to be demanding.

Note that the code I posted is not exactly the same as in the Hacktronics tutorial I recommend, but modified to be more easily expanded upon.

Thanks, I'll post back with how I get on later :slight_smile:

Still cannot work this out unfortunately

Scanner didn't seem to pick up the sensor... BUT, I still don't think that is the issue, I think it is more my wiring or something else (since the sensors are brand new and they don't seem to have an affect on the figure)

Pic below of my breadboard.

So the cable in 20 is going to ground. 18 is going to 15. 15 has the resistor in and goes to 19, which goes off to pin 3 on my arduino. And then the red cable is bringing in 5v to the + rail on the breadboard, connecting a wire from this into row 15 causes the sensor to smell and begin to get VERY hot, so it is not plugged in. But that is following this image from the hacktronics site:

Despite how it looks in the pic, the resistor in 19 is not actually touching the wire in 18

The code being used is from various places, I've tried that one you supplied and also this from a youtube video

#include <OneWire.h>

#include <DallasTemperature.h>

OneWire oneWire (3);

DallasTemperature sensors(&oneWire);

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

void loop()

{
 sensors.requestTemperatures();
 float currentTemp;
 currentTemp = sensors.getTempCByIndex(0);
Serial.print(currentTemp); 
 delay(1000); 
}

Thanks!

I've also tried giving the 5v direct from a bench power supply that gives out 5v, still the same issue so it isn't power related.

Looks to me like you've wired the DS18B20 backwards. Unless there's some trickery/rerouting of signals on the breakout board, 18 is power, 19 is signal and 20 is ground. You've got power and ground reversed which will tend to annoy the DS18B20 :slight_smile:

Where did you get that breakout board from and did you solder the DS18B20 on it yourself?
The diagram in your original post suggested that you had just the DS18B20 device without a breakout board.

Pete

That is how I purchased it from here:

http://www.gearbest.com/development-boards/pp_76243.html

So just to confirm, from that picture on the website (as it is clearer), what should I have plugged where?

When you say "18 is power, 19 is signal and 20 is ground. ", that is what I already have

Based on the picture, what should be in the pin with the '-' next to it from the gearbest site, ground or power?

Thanks! :slight_smile:

Are you sure it it at DS18B20 sensor on that module ?
It looks like there is at 4K7 resistor already mounted on the senser board ? And it's hard too see how the connection pin on the module are connected too the Dallas sensor.
Have you tried bying at "naked" DS18B20, it's pretty easy too Work with.

Definitely a DS18B20, I can see it written on the back of the 'head' of the sensor

I will try it without me adding an extra resistor and see what happens

I may have to buy a 'naked' one instead, just a shame as these took so long to arrive haha

I've asked the company to see if they can assist with info on how it should be wired

Otherwise I'll just have to order standard ones.

Am I right in saying there should NOT be any extra complications just because I'm using an Arduino Yun over something like an uno?

Sorry, I must have had my brain in backwards this afternoon.

Have you got a multimeter? If so, take the breakout board out of the breadboard and just test connectivity between the pins on the breakout board and the leads on the DS18B20 just to make sure there's no trickery on the board - i.e. the left pin does connect to the left lead (as viewed in the photo).

Pete

I do have a multimeter with continuity test feature

I'll have a look at this over the weekend and post back, thanks :slight_smile:

That poor red wire, looks like it was fried a bit there. First thing I would do is snip off that burnt end and strip it down to some fresh copper.

Thanks el_supremo!! I think you've helped me work it out! There IS some trickery on the board and the pins do not match up left to right, I'll re-wire it (probably tomorrow) now I know which pin is which and hopefully it will work

Elac I've got some proper breadboard jumper wires now so that red one can go in the bin :smiley:

The same board is obviously used for different devices such as this one which uses the middle row of connections. That board also has the 4k7 resistor and what I presume is a Led. This made me wonder if the outputs at the header pins might not be in the same order as the ds18b20 pins.

Let us know which way round the pins are connected if you get it working.

Pete

You are correct el_supremo

The resistor is on the board already, as well as what seems to be a status LED. If connected incorrectly it either flashes slowly or doesn't flash at all. If connected correctly it flashes quickly

So pins are all shifted to the right one (and far right one is the far left pin)... Looking at the board from the front:

Left hand pin at the top (positive) is middle pin at the bottom
Middle pin at the top (signal) is right hand pin at the bottom
Right hand pin at the top (ground) is left hand pin on the bottom

Thank you so much for all the help in trying to diagnose this, feels so good to finally have it working... Was nearly giving up haha

Thanks all :slight_smile:

Note: I couldn't get parasite power working, but I was warned about that by another member here before I began the project