DS18B20 value -127º, but only when connecting to Blynk, on ESP32

While I am sleeping… play around with the timing… perhaps increase the delay to 1000 or 2000 (1 or 2 seconds between disconnecting and checking the temp).

writes sleeping too, from what I see… :rofl::rofl::rofl:

continues with the same reading.

Just checking you read the Dallas Temperature lib readme

You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line
and your 3 or 5V power. If you are using the DS18B20, ground pins 1 and 3. The
centre pin is the data line ‘1-wire’.

and there is a special way to power it in the datasheet.
Scroll to page 7… “powering the DS18B20”

Honestly I would go with a simpler sensor

i have heaps of these running around the place, they could not be much simpler than these sensors…

2 Likes
void readDS18BFunction()// this function gets the temps from the DS18B sensors
{
  if (debug)
  {
    Serial.println(F("runDS18BFunction() activated - requesting temps from DS18B probes"));
  }

  DS18Bsensor1.requestTemperatures(); //the first one (duct)
  rawDS18Bsensor1 = DS18Bsensor1.getTempCByIndex(0);

  Blynk.virtualWrite(V61, rawDS18Bsensor1); //this is sending the temp to virtual pin in the Blynk app

  if (debug)
  {
    Serial.println(F("DS18B Sensor 1 temps:"));
    Serial.print(F("Raw:"));
    Serial.print(rawDS18Bsensor1);
    Serial.println(F("'C"));
  }

   if (debug)
  {
    Serial.println(F("finished doing temps from DS18B set"));
    Serial.println(F("----------------------------"));
  }
}

that’s how i do it on ESP8266-12E.

1 Like

The OP’s issue is NOT how to get it to work, he has already shown it fully functional… rather why it is so flaky (apparently when the WiFi/Blynk connection is active) on an ESP32?

I have an ESP32, but none of those 1-wire sensors to test my theory.

Exactly.

I made it work perfectly connected to BLYNK with Nodemcu (esp8266), but with esp-32 it does not work when connected to BLYNK.

i was going to say it was probably a hardware issue, but i hadn’t read the whole thread…

1 Like

I have now tested all these pins in the other esp32 and the problem continues.
I’m getting a little discouraged, but I have to find the problem because it can be useful for other people as well.

Espressif, the makers of the ESP32 chip, are still ironing out the bugs in the firmware and core IDE code for the ESP32.

So, if the issue is some form of interference between OneWire/Blynk/WiFi libraries, due to the firmware, then the problem and solution, may be out of our control.

I do not have any sensors like that for my own testing… and even if I could budget for them (yes, things are that tight for me :frowning: ) then it would still take weeks/month before I even received them… so, based on what we have seen so far… works until Blynk connects… all I can do is suggest further experimenting with the timing of enabling/disabling Blynk connection to see if there is a workaround.

On that note… lets run another test code. To confirm when the sensor reading work and fail… this will scan the sensor 10 times before connecting to Blynk and resuming the scan… please run it and show the Serial monitor output:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>
char auth[] = "be36298205ca4bccb6d507c1ed6edc17";
char ssid[] = "REDE DS";
char pass[] = "1234554321";

#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 5  // set the GPIO pin that the sensor is connected to
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;

BlynkTimer timer;

void temperatura()
{
  Blynk.virtualWrite(V10, millis() / 1000);
  Serial.println("Getting Temp");
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);
  Serial.println("TEMPERATURA: ");
  Serial.println(temp);
}

void setup()
{
  DS18B20.begin();
  Serial.begin(115200);

  for (int i = 0; i <= 10; i++) {
    temperatura();
    delay(1000);
  }

  Blynk.begin(auth, ssid, pass);

  timer.setInterval(1000L, temperatura);
}

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

No issues from my side playing with the Esp32 and the DS18b20…
There’s something missing here but I have no clue about it…

1 Like

Hmm… OK, then perhaps @thiagopai is running an older version of the ESP Core in his IDE?

Anyone know how to tell what version core for ESP is being actively used in Arduino IDE?

I just ran my Git GUI update and this is all it really shows:

Do you have a esp-32 running with ds18b20 and BLYNK online?
Can you put your code here so I can test with it?

Yep, no worries
Once at home I’ll post it here

OK thank you.

HI @thiagopai,

Check this code. (@Costas, I’m sure this code is familiar to you… :wink:)

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h> //Sensor Temp
#include <DallasTemperature.h> //Sensor Temp
#define Pin 12//  pin DATA ds18b20
OneWire oneWire(Pin); // OneWire PIN DATA
DallasTemperature sensors(&oneWire); //Se instancia la librería DallasTemperature
BlynkTimer timer;
float temp;

//********************* SECTION FOR YOU TO COMPLETE WITH YOUR DETAILS *************
// Get Auth Token in the Blynk App.

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; //
char cloudserver[16] = "blynk-cloud.com";
char localserver[16] = "xxx.xxx.xxx.xxx";          // Enter your IP details for the local server
char ssid[] = "ddddd";                   // Your WiFi credentials.
char pass[] = "wwwwwwww";                     // Set password to "" for open networks.
//*********************************************************************************

//********************* CLOCK DETAILS *********************************************
#include <WidgetRTC.h>//Blynk
WidgetRTC rtc;
//*********************************************************************************

bool isFirstConnect = true;

BLYNK_CONNECTED() {
if (isFirstConnect) {
timer.setTimeout(2000, notify_start);
isFirstConnect = false;
}
}

unsigned int myServerTimeout  =  3500;  //  3.5s server connection timeout (SCT)
unsigned int myWiFiTimeout    =  7500;  //  7.5s WiFi connection timeout   (WCT)
unsigned int functionInterval =  7500;  //  7.5s function call frequency   (FCF)
unsigned int blynkInterval    = 25000;  // 25.0s check server frequency    (CSF)


void setup()
{ 
sensors.begin();// Sensor  

 // Debug console
 Serial.begin(115200);
 Serial.println("\n Starting");
 if(WiFi.status() == 6){
    Serial.println("\tWiFi not connected yet.");
 }
  //Blynk.begin(auth, ssid, pass);              // normal Blynk Cloud server connection     
 // Blynk.config(auth, cloudserver);            // for Blynk's cloud server if WiFi already connected
 //Blynk.begin(auth, ssid, pass, localserver);   // for a local server requiring WiFi connection
  
  timer.setInterval(2000, leeTEMP);
  timer.setInterval(15000, checkBlynk); // check every 15 seconds if we are connected to the server
  timer.setInterval(5000, clockvalue);  // check value for time
  timer.setInterval(5000, sendWifi);    // Wi-Fi singal
  timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval
  unsigned long startWiFi = millis();
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){
    delay(2000);
    if(millis() > startWiFi + myWiFiTimeout){
      Serial.println("\tCheck the WiFi router. ");
      break;
    } 
  Blynk.config(auth, cloudserver);
  checkBlynk();
  } 
rtc.begin(); //RTC CLOCK BEGIN
}

void notify_start (){
Blynk.notify("ESP32 Starting!");
Blynk.syncAll();
}

void checkBlynk() {
  if (WiFi.status() == WL_CONNECTED)  
  {
    unsigned long startConnecting = millis();    
    while(!Blynk.connected()){
      Blynk.connect();  
      if(millis() > startConnecting + myServerTimeout){
        Serial.print("Unable to connect to server. ");
        break;
      }
    }
  }
  if (WiFi.status() != 3) {
    Serial.print("\tNo WiFi. ");
  } 
  Serial.printf("\tChecking again in %is.\n", blynkInterval /1000);
  Serial.println(); 
}


void leeTEMP()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  Serial.println("TEMPERATURE: ");
  Serial.println(temp);
  Blynk.virtualWrite(V0, sensors.getTempCByIndex(0));
 
   
}

void sendWifi() {
  
 int wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
  Blynk.virtualWrite(V1, wifisignal);  
  
}


void clockvalue() // Digital clock display of the time
{  
 int gmthour = hour();
  if (gmthour == 24){
     gmthour = 0;
  }
  String displayhour =   String(gmthour, DEC);
  int hourdigits = displayhour.length();
  if(hourdigits == 1){
    displayhour = "0" + displayhour;
  }
  String displayminute = String(minute(), DEC);
  int minutedigits = displayminute.length();  
  if(minutedigits == 1){
    displayminute = "0" + displayminute;
  }  

  String displaycurrenttime = displayhour + ":" + displayminute;
  Blynk.virtualWrite(V2, displaycurrenttime);
}


void loop()
{
if (Blynk.connected()) {   // to ensure that Blynk.run() function is only called if we are still connected to the server
    Blynk.run();
} 
timer.run();
}

2 Likes

Thanks friend for the code, I compiled here and I continue with the same problem, I believe it’s something with the library I’m using, I can not imagine anything else.
Would you like to send me your library or give me a link from where you got it?

I might also be related to the version of ESP/Arduino core you are running for the ESP32.

Did you install and do you keep it updated using the GitGUI method?