Weird behavior DS18b20's and ESP8266

I have a temp monitoring setup that includes an Esp8266 with 2 DS18B20's, showing readings on an OLED display and publishing to MQTT for monitoring my garage fridge/freezer.

The two DS18B20's - 1 is mounted in my fridge, and the other in the freezer portion. Prior to putting the sensors in the fridge everything worked great. Once in the fridge everything works for about 12 hours, and then I get sporadic weird readings. And they always come back with a weird reading of something like 9 F freeze and 8F fridge. It will give this bogus reading every 2-3 readings (With the other readings being correct).
If I take the one lead out of the freezer, and leave it in the open....Everything will work perfectly. Fridge temp is correct, and the freezer temp (now outside the freezer) reads correct.
Put the lead back in the freezer, will work for about 12 hours, and then same problem.

And yes I do have the 4.7K resistor.

Any thoughts ideas?

Have you tried using non-parasite power?

I'm running all 3 wires, hooked up to 3.3V on the esp8266. 4.7K resistor across power and signal.
I thought this config was non-parasitic power.....

It is, but I think the 4.7 is questionable @ 3.3v. There was recent discussion about this. Having said that, I doubt it is your problem, and I reckon it is something mechanical. Maybe the sensors, while quite capable of reading such temperatures, are not really up to working in that environment.

if 4.7 is questionable, what is recommended?

There is discussion on this nearby but I can't find it. Here is a clip that is a few years old.

Hi All, for anyone who has this same problem of a DS18B20 on the NodeMCU. I can confirm changing to a 2.2K resistor helps. However please note, the 'Simple' example code for the Dallas Temperature library includes:

#define ONE_WIRE_BUS 2

On the NodeMCU you must define the pin as "D2" rather than just "2" otherwise it wont work.

I've been running a set of multiple DS18B20s in my spa and another set in my refrigerator/freezer for years with no problems.

These are both three wire setups using a 4.7K pull-up.

When I initially started I selected GPIO2 (D4) for the input since it is right next to the power pins on the nodeMCU devices and I have continued to use that pin over the years with both the nodeMCU and Wemos (Lolin) devices.

Well - it turns out that that particular pin already has a 12K pull-up on the board so my effective resistance is about 3.38K which may explain why I have had no trouble.

Don

On the NodeMCU you must define the pin as "D2" rather than just "2" otherwise it wont work.

Are you sure about that? I think your choices are "D4" or just "2".

Let me rephrase that:

  • If you are using GPIO2 you can use "D4" or "2".
  • If you are using GPIO4 you can use "D2" or "4".

Wasn't that clever of them....

.

Don

(Groan).. so what the guy I clipped from was really saying was
"you define the pin as D2, rather than just 2, and when doing so, you connect it to GPIO 4."

Actually, now with a NodeMCU in my hand, it isn't so incomprehensible. GPIO 4 is actually Pin D2 so, for my device at least, this is only about the wording in the code - you define "D2" and you connect to D2 (?). The "GPIO 4 "isn't actually material.
I was inclined to use D0 - GPIO 16, but I think I might standardise on D4 as well.

D4 - GPIO 2 works out well since you can still add SPI and I2C devices.

Don

I appreciate the posts, but I'm not sure how the discussion on which pin to use is relevant. For my project it was defined this way:

// Data wire is plugged TO GPIO 14
#define ONE_WIRE_BUS 14

Again, pull the sensor out of the freezer, and leave it outside....No more false readings.

Any ideas?

Hi Suntzu,

let me try to help you. I am very newbie but I am using DS18B20 on both ESP32 and MEGA 2560 for my first project, and honestly (unless it is not wired correctly) it is the only sensor that never give me troubles.

Anyway I am powering them with 5V and I think it is mandatory to use 5V.

If you are able to power it with 5V try to do it and let us know!

Cheers,
F

Ok.. it seems not mandatory 5V from the datasheet, but most scheme I have seen power them with 5V and I don't know why I noted down on my project draft to use 5V.

Anyway it worths a try!

Take care if you are powering the DS18B20 from 5V and using ESP32.
The ESP32 is a 3.3V device, so I think you need to protect it from the 5V from DS18B20 data pin.
/ffur

Amen to that. I understand ESPs are very sensitive to voltage, DS18B20 is good down to 3v, so why complicate matters unnecessarily?

suntzu44:
I appreciate the posts, but I’m not sure how the discussion on which pin to use is relevant. For my project it was defined this way:

// Data wire is plugged TO GPIO 14
#define ONE_WIRE_BUS 14

Again, pull the sensor out of the freezer, and leave it outside…No more false readings.

Any ideas?

Which pin to use is relevant only because in some cases the board already has a pull-up resistor connected to the pin. This will affect whether or not you need an external pull-up, and if you decide you do, it will affect the size to use.

In my case I am using a 4.7 K external pull-up with my device running at 3.3 volts. This appears to be the same as your setup except that you are using GPIO 14 and I am using GPIO 2.

The difference is that GPIO 14 has no internal pull-up so your effective pull-up resistance is the same as the resistor that you are using or 4.7K.

I am using GPIO 2 which has an internal 10K pull-up. This means that my effective pull-up resistance is the parallel combination of the internal 10K and my external 4.7K or about 3.4K.

This leads me to believe that if you were to use a 3.3K pull-up on your ESP8266 GPIO 14 pin you will have a combination that is similar to the one that has been working for me for quite a while.

EDIT: Check it out at Refrigerator-Freezer-Ambient - ThingSpeak IoT.
Note: if you are a visitor from the future I can’t guarantee that this link will still be working or still display the ESP8266/DS18B20 setup, but right now that’s what is there.

Don

To add bit more information. It's a Wemo D1 Mini Esp8266. And yes 3.3v. The spec sheets for DS18b20's are 3V-5V. So 3.3V should not be a problem.

2 Sensors -1 in the fridge and 1 in the freezer.

I have the exact same setup outside monitoring my hot tub. 1 sensor in ambient air, and 1 sensor in the hot tub. No false readings.

At this point, I'm still scratching my head. How is temperature impacting the esp8266?...remember per my original post....It causes to give bogus readings on both sensors.....Take the ds18b20 out of the freezer, and it stops giving false readings.

I've used the db18b20 on several esp8266s. 3.3v has never been a problem.

Don...Appreciate your update. Will look into it.