DS18B20 not working with deep sleep

I had deep sleep working and the temperature was working as normal. Then without any hardware adjustments I am getting the -196.6 F all the time and I have no idea why. I have used this sensor code in other places so I not sure whats wrong. Does anything look out of place? I have removed deep sleep and that didnt help anything so I doubt its that but that is the only new code I am using in this sketch.

//////////////////////BLYNK CODE
#define BLYNK_PRINT Serial  
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
const char* ssid = "*";
const char* password = "*";
char auth[] = "*";
WidgetTerminal terminal(V3);

//All pin settings
////Sensor Initialization
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#define ONE_WIRE_BUS D4 //Sensor location
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensor(&oneWire);

/////Deep Sleep Time
float sleepTimeH = .1; //Number of hours

//////////////////////BLYNK CODE
bool isFirstConnect = true; // This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
  if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;  
  }
}

void calc(){
  sensor.requestTemperatures();
  float temp = sensor.getTempFByIndex(0);
  terminal.print("Temp:");
  terminal.println(temp);
  terminal.flush();
  Blynk.virtualWrite(V1, temp); // virtual pin 
  ESP.deepSleep(sleepTimeH*60*60*1000000);
  delay(100);
}

void setup() 
{
  sensor.begin();
  sensor.setResolution(9); //Resolution of 9 means 0.5degC increments.
  Serial.begin(115200);
  Blynk.begin(auth,ssid,password);
  timer.setInterval(5, calc);
  //client.wifiConnection(WIFISSID,WIFIPASSWORD);    
}

void loop() 
{
  Blynk.run();
  timer.run(); 
}

That generally means the sensor is not being read correctly (in a sense that number is an error reading).

I have found these sensors are sensitive to the supplied current… when testing mine, I couldn’t get any other result until I tried my third 3.3v power source… the 3.3v current from the ESP wasn’t enough.

You also may not be giving the sensor enough time to actually get a reading before putting the ESP to sleep… Your timer is a bare 5ms…and from what I can tell, basically meaningless in it purpose anyhow, even if longer, as it is only waiting before processing the temp reading… which then processes the sleep command immediately after as the only other delay you have comes after the sleep command… thus never actually gets processed.

Can’t see why this would matter as the temperature request and response is done before getting to the deep sleep line?

I’m more interested in if he is wired up properly, with a pull up on the data line… I’ve noticed on my multimeter that i get a current spike of ~500uA when the temp meter is doing a reading, with a 10k pull up on my wemos d1 mini.
With that number, if esp is even on there shouldn’t be an issue with power since it’s a minimal current in comparison :slight_smile:

//////////////////////BLYNK CODE
#define BLYNK_PRINT Serial  
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

const char* ssid = "*";
const char* password = "*";
char auth[] = "*";

WidgetTerminal terminal(V3);

//All pin settings
////Sensor Initialization
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS D4 //Sensor location
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensor(&oneWire);

float temp = 0;
/////Deep Sleep Time
float sleepTimeH = .1; //Number of hours

BLYNK_CONNECTED() 
{	
	Blynk.virtualWrite(V1, temp); // virtual pin 
	Serial.print("Send Data Blynk server is OK!");
	terminal.print("Temp:");
	terminal.println(temp);
	terminal.flush();		
}

void setup() 
{
	sensor.begin();
	sensor.setResolution(9); //Resolution of 9 means 0.5degC increments.
	sensor.requestTemperatures();
	delay(1000);
	temp = sensor.getTempFByIndex(0);	
	Serial.begin(115200);	
	Blynk.connectWiFi(ssid, pass);
	Blynk.config(auth);
	Blynk.connect(); 	
	ESP.deepSleep(sleepTimeH*60*60*1000000);
}

void loop() 
{
  //TODO
}

@philmurp I corrected the code for you. It should work. If not, it’s about hardware. If there is no WiFi connection - will not go to sleep. We will need to modification the code. Leave you the opportunity to show your creativity.

This wont do anything to help the temp read, if you don’t believe me read the library yourself.
All the delays that need to happen are done in the call to .requestTemperatures, dictated by what resolution is set.
Once requestTemperatures is done the temp read is complete, delay after that wont to anything to the reading.

I have the same issue whether plugged into a computer USB, USB power bank, directly to the wall via charger; so I have tried it with different power sources.

It is wired to the 3.3V pin on the Wemos; would changing it to the 5V Wemos pin help? I thought Wemos only ever outputs 3.3V anywhere you connect it.

As far as the timer, I purposely have that very low because I want the temp code block to run as soon as the unit wakes up. I tried this code with an accelerometer I had and that gave perfectly fine readings so I am inclined to this it isn’t the small timer cycle time.

I do have the pull up on data line, 4.7K Ohm.

Have you tried another sensor to rule out it being defective

It seems more the current rating than the voltage. The current output of the 3.3v pin on the Wemos may not be high enough… at least it wasn’t in my case. Strangely, my ESP32 did have enough current to power multiple sensors (3 of them so far)… Go figure.

Yes, you could power the sensor via 5v as well, and that should supply enough current… there is the debatable issue of whether the 5v signal will or will not be detrimental to the ESP8266 input pins… but particularly for short bursts as in your case I wouldn’t worry about it.

I guess I had overlooked this part… If not any hardware changes, then what software changes have been made recently? App, server, ESP Arduino/IDE core, etc.

That’s the weird thing, I had it plugged in and working and then came back a week later (a week without the device running) and it gives me this error, I think I am going to have to re-solder; and then if that doesn’t work buy a new one. But all connections look good still. Frustrating.

Wemos regulator should be RT9013 or similar, capable of outputting 500mA, even at esp peak load of 250~ mA it’s more than enough left over for peripheral sensors :slight_smile:

You are right… my mistake, I was using one of those breadboard power supplies that while rated <700ma was also powering other circuits, including an ESP-01. Now that I think back on it, while I have used these DS18B20 sensors on an Arduino, ESP-01 and ESP32… I have NOT actually used any on a Wemos D1 Mini :blush:

1 Like

@philmurp I bought DS18B20 probes from two different suppliers. Neither would work at 3.3V but they were fine with Arduino’s at 5V. A Blynker put me on to a supplier of DS18B20 probes that do work at 3.3V. Ordered a few dozen, all tested as working.

Maybe you have “5V” sensors like the ones I received.

My favorite three words from you :wink:

1 Like