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

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.

Please run this code (do not comment out anything else for now) and show your serial monitor output.

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#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.print("TEMPERATURA:  ");
  Serial.println(temp);
  Serial.println(millis()/1000);
  //Blynk.virtualWrite(V10, millis() / 1000);
}

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

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

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

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

OK, good… it looks like is not the Blynk library so much as a possible issue when communicating over WiFi

You say you have tried ALL the pins (even the RX/TX?) :stuck_out_tongue:

Can you try again, but with one of these pins - 16, 17, 18, 19

With this code - and make sure to change the pin number in this line as well: #define ONE_WIRE_BUS 15

#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 15  // set the GPIO pin that the sensor is connected to
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;

BlynkTimer timer;

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

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

  //Blynk.begin(auth, ssid, pass);
  
  timer.setInterval(1000L, temperatura);
}

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

OPPs… I meant try changing the pins but also while connecting to Blynk… so just uncomment the lines I have commented out.