BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

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

If I remove the part of the code responsible for connecting with the Blynk the sensor works normally.
My code below.
My hardware is an esp-32.

// inicio BLYNK ***********************************************************
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "****************";
//fim BLYNK  *************************************************************
    

//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h> 
#define ONE_WIRE_BUS 13 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura


void setup() {
  // put your setup code here, to run once:
        Serial.begin(115200);
        Serial.println();
        Serial.println();

      //BLYNK
      Blynk.begin(auth, ssid, pass);

      
      //Inicializa SENSOR TEMPERATURA
        DS18B20.begin();

}

void loop() {
  // put your main code here, to run repeatedly:
      //BLYNK
  temperatura();
  delay(1000);

}

void temperatura() 
{
  //inicio SENSOR TEMPERATURA  
 DS18B20.requestTemperatures(); 
 temp = DS18B20.getTempCByIndex(0);
 Serial.println("TEMPERATURA");
 Serial.println(temp);
 Blynk.virtualWrite(V10, temp);
}

@thiagopai you shouldn’t call temperatura() in loop() even with the 1s delay. See PUSH_DATA example for calling the same function at 1s intervals.

Even with the modification done as shown in the code below, the problem continues.:desapontado:

#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " *********** ";

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = " ************ ";
char pass[] = " ******************* ";
//fim BLYNK *************************************************************

//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 15 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura

BlynkTimer timer;

void temperatura()
{
  //inicio SENSOR TEMPERATURA
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);
  Serial.println("TEMPERATURA");
  Serial.println(temp);
  Blynk.virtualWrite(V10, temp);
  delay(1000);
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  //BLYNK
  Blynk.begin(auth, ssid, pass);

  
  //Inicializa SENSOR TEMPERATURA
    DS18B20.begin();
    timer.setInterval(1000L, temperatura);
}

void loop() 
{
// put your main code here, to run repeatedly:
//BLYNK
  Blynk.run();
  timer.run();
}

I would always put this as the first line of setup().

You could try changing 1000L to 2000L but 1000L should be fine.

Do you have a 4K7 fitted to the DS18B20?

yes.

I did it now and the problem continues.

If I write the code below, it works normally.
I just commented the part of the blynk and put the “temperature ();” in the loop.

/*
// inicio BLYNK ***********************************************************
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "be36298205ca4bccb6d507c1ed6edc17";

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = "REDE DS";
char pass[] = "1234554321";
//fim BLYNK *************************************************************
*/

//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 15 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura

//BlynkTimer timer;

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

void setup()
{
  DS18B20.begin();
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  //BLYNK
  //Blynk.begin(auth, ssid, pass);

  
  //Inicializa SENSOR TEMPERATURA
    //timer.setInterval(1000L, temperatura);
}

void loop() 
{
// put your main code here, to run repeatedly:
//BLYNK
  //Blynk.run();
  //timer.run();
  temperatura();
}

Reinstate Blynk and paste Serial Monitor from the start. Just wondering if you are failing to connect to the Blynk server and it’s too busy trying, and failing to connect, to be able to read the sensor.

@thiagopai I have fixed your last few posts… Please follow the required method for formatting pasted code in this forum…

Blynk - FTFC

ok.

If anyone else can help, thank you very much, my project is stopped, and I am still trying to find a solution to this.

Try commenting out Blynk.run() & Blynk.begin(), but keeping the timer.run() and the timed temp reading (it is NOT reliant on Blynk).

It works perfectly the temperature reading, but BLYNK goes offline, how to keep temperature reading with BLYNK online?

So, to confirm, it works with the timer as well as without (as you have tested before)?

Blynk itself shouldn’t affect how it reads that sensor… unless there is some strange incompatibility with something in the Blynk library and the relatively “new to Blynk” ESP32.

Have you tried any other pins on the ESP32… as many have multiple applications and perhaps may contribute to the conflict.

Also, perhaps try a different library for that sensor…might work better with Blynk?

I’ve tried all the pins, and the temperature reading only shows -127º and the actual temperature when the application is connected to Blynk.
I noticed that when connected to Blynk, the Gauge widget used to show the temperature initializes with a value of 0 and each reading increases by 1 unit to the value. 1,2,3,4,5,6,7, …

and… ?

I am trying to work a process of elimination here… we already know that -127 is a default error reading and we are currently not worried about widgets…since you are also seeing the error in the serial monitor…

So… please confirm my question, and if possible test that other library.

I did not understand

I have now tested the new library you indicated to me and the problem continues.