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

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

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.

I found that yesterday, search engines are so useful and I’m guessing here, but there’s probably a whole bunch of web pages that even show you how to use search engines :slight_smile:

It does not work on RX and TX, the readings are always -127º with BLYNK or without BLYNK.

I typed “How to search on Google” into Google once… I am still cleaning up the mess from the vortex :stuck_out_tongue:

1 Like

ESP32 certainly has some problems with pins and WiFi. Not entirely related but 8 of the analogue pins (ADC1) are OK with WiFi, the other 10 (ADC2) are not. A fix is supposedly imminent but just another reason I’m not a big fan of ESP32’s.

One day they will rock the world but still a long way to go until they are as reliable as the ESP8266.

I was being a bit sarcastic when mentioning those pins… as in you couldn’t have tested with ALL pins :smiley:

Just try the last code, but with those other pins I mentioned… with Blynk running… they seem to be some of the most basic pins on the ESP32 lineup.

What pin where you using? Please try the others now. Thank you.

I was able to use pin 16 because my esp-32 has an oled that uses some ports

I have another esp32 that does not have the oled but is at home.

PINS_ESP32_OLED

Ahhh… the OLED is taking all the good pins :stuck_out_tongue:

Try pin 5

:rofl::rofl::rofl::rofl::rofl::rofl:

OK, final test for me… need to sleep…

try this code on pin 5… every 10 seconds it will (should) disconnect from the server, read the temperature and reconnect.

#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.disconnect();
  delay(10);
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);
  Blynk.connect(5);
  Serial.println("TEMPERATURA: ");
  Serial.println(temp);
  Blynk.virtualWrite(V10, millis() / 1000);
}

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

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

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

OK, thanks for the help.

Well it was a shot… not sure what else to try, but I will think about it and check in later.

:clap::clap::clap::clap::clap::clap::clap::clap:
:+1: