DS18B20 virtual pin not working

Hi all,
I’m lost with a very simple script: retrieving data from a DS18B20.
I spent last 3 hrs aroud it… no solution.

  • Script is quite basic, in terms of errors everythink is fine (no mistake by Arduino IDE)
  • In terms of data I can see from serial monitor data coming right (so in terms of wiring and connection everything is fine)
  • I see the node mcu on line

but… my “Labelled Value” box still 0.00 where I’m wrong? It’s connected to V1

Here my code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D2); // digital D2 pin
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
char auth[] = "f9c1ZZZZZZZ4cb";

// Your WiFi credentials.
char ssid[] = "YYY";
char pass[] = "XXX";

float  temp = 0;

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
// Setup a function to be called every second  
  timer.setInterval(1000L, sendTemps);
}

void sendTemps()
{
 sensors.requestTemperatures();
 temp = sensors.getTempCByIndex(0);
 Blynk.virtualWrite(V1, temp);
 Serial.print("Temperature for the device is: ");
 Serial.println(sensors.getTempCByIndex(0)); 
}

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

Here a print screen where I got numbers in serial monitor:

What happens if you change this line:

 Serial.println(sensors.getTempCByIndex(0)); 

to this?:

 Serial.println(temp);

The reason for the question is that your sendTemps() function is taking a temperature reading and saving the result to the variable temp. You’re then sending this value to Blynk. Rather than also sending the same value to the serial monitor, you’re taking a new reading and sending it to the serial monitor.

It could be that the the first time a temperature reading is taken is a little soon after the sensors.requestTemperatures(); command, but the second time the reading is taken it returns a result. Making the change shown above will prove or disprove this theory, but at least we’ll then know that EXACTLY the same data is being sent to both Blynk and the serial monitor.

Pete.

2 Likes

what do you see if you replace by

Serial.println(temp); 
1 Like

oooops
you are faster than me. @PeteKnight
:blush:

Hi, thank you for your fast answers :slight_smile:
Ok, it made this chance

Here updated code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(D2); // digital D2 pin
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
char auth[] = "XXXXXXX";

// Your WiFi credentials.
char ssid[] = "YYY";
char pass[] = "ZZZ";

float  temp = 0;

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
// Setup a function to be called every second  
  timer.setInterval(1000L, sendTemps);
}

void sendTemps()
{
 sensors.requestTemperatures();
 temp = sensors.getTempCByIndex(0);
 Blynk.virtualWrite(V1, temp);
 Serial.print("Temperature for the device is: ");
 Serial.println(temp);  
}

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

in the code but result still the same;
I see numbers in serial monitor but it still 0.00 in the Blynk App

Here the setting on App:

Ok
try float temp instead of float___ temp without =0 and no more space between float and temp

float temp;

instead of
06209

Hi Blynk_Coeur,
I edit the file without luck :frowning:
The UI still showing 0.00

here code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(D2); // digital D2 pin
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
char auth[] = "XXX";

// Your WiFi credentials.
char ssid[] = "YY";
char pass[] = "ZZ";

float temp;

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
// Setup a function to be called every second  
  timer.setInterval(1000L, sendTemps);
}

void sendTemps()
{
 sensors.requestTemperatures();
 temp = sensors.getTempCByIndex(0);
 Blynk.virtualWrite(V1, temp);
 Serial.print("Temperature for the device is: ");
 Serial.println(temp);  
}

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

I really don’t understand :thinking:

Just to confirm, you’ve uploaded the new code to your NodeMCU and it uploaded correctly without any errors?

The reason for asking is that I’ve wasted time before thinking that I was running updated code when it was still using the old version of the code because the upload failed and I hadn’t noticed :roll_eyes:

Pete.

1 Like

Hi PeteKnight,
doublechecked. It shows 100%…

One more, just to confirm. You have the App running? That is, you have pressed the play button on the upper right hand corner?

what is your release ?
06210

Hi Toro_Blanco,
to avoid any confusion I killed the app (IOS) and restarted.
That said I always check the connection status; when the code is uploaded I usually lose the nodemcu for few second (new code is uploaded).

@Toro_Blanco the serial monitor print zero too … :wink:

@Blynk_Coeur, I was under the impression it was only BLYNK that was not displaying the dtat.

1 Like

Hi Blynk_Coeur,
here what I see in the serial monitor (the right temperature)

so if you see

Serial.println(temp);  

that is to say “temp” is ok
so there is probably a problem with the widget :thinking::thinking:

Hi Blynk, yes the problem is 100% on the widget / virtual write.
I tried also generating a new Labeled Diplay - Value Display - Gauge… result still the same…

Can we see the full output from the serial monitor, from boot-up please?
Select it in the serial monitor using CTRL A and copy using CTRL C then paste it into the forum with triple back-ticks at the beginning and end.

Pete.

Hi Pete, is it ok?

Temperature for the device is: 23.81
Temperature for the device is: 23.81
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87
Temperature for the device is: 23.87