DHT11 sensor not sending data to Blynk

Hello, new to Blynk to coding MCUs overall, so I’m begging for help. I’m using standalone Atmega328P with ESP8266 and Arduino power supply module for reading measurements from DHT11 sensor. It is valid with connecting to Blynk, but whenever I try to output the value from datastreams to Label widgets, it’s not showing actual values and doesn’t change as time passes. I rechecked that my datastreams are connected to widgets. Please some advice

/* Fill in information from Blynk Device Info here */

#define BLYNK_TEMPLATE_ID "TMPL4Br9ZPHq3"
#define BLYNK_TEMPLATE_NAME "Weather device"
#define BLYNK_AUTH_TOKEN "K6fzuHBkzN6pJ-N8-gUuphBpZ-FhrRvv"


#include <SPI.h>
#include <DHT11.h>

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Muster";
char pass[] = "nxbn9777";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200 //default baudrate

ESP8266 wifi(&EspSerial);
#define DHTPIN 6
         // What digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT11 dht11(DHTPIN);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5)
void sendSensor()
{
  float temperature = dht11.readTemperature();
  float humidity = dht11.readHumidity(); // or dht.readTemperature(true) for Fahrenheit
  delay(50);

  if (isnan(humidity) || isnan(temperature)) {
    Blynk.virtualWrite(V3, 1);
    return;
  }
  else {
    Blynk.virtualWrite(V3, 0);
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, humidity);
  Blynk.virtualWrite(V1, temperature);
}

void setup()
{
  // Debug console
  Serial.begin(19200);
 

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass, "blynk.cloud", 80);

  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}

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

A really poor choice of hardware for your first experiments with IoT systems.
You’d be better choosing an IoT capable board such as a NodeMCU or ESP32, and a better temperature/humidity sensor than the DHT range.

I’m really surprised that you manage to get your device online with Blynk, because SoftwareSerial can’t normally cope with baud rates higher than 9600…

I’m not sure which DHT library you’re using. The Blynk examples normally use a library called DHT.h which is installed via the Arduino IDE, but you’re using a library called DHT11.h.
Where did you find this library? What library version are you using, and how did you install it?

Your serial monitor is then easiest way to figure-out what’s happening within your sketch, especially if you add Serial.print statements to output the readings from your sensors as well as sending these readings to Blynk.

Pete.

Hey again, thanks for your corrections. I changed the baud rate of both Serial and my ESP module and now did the output to Serial monitor of data my sensor reads. It does give valid values but still when I connect the datastreams to widgets in Dashboard it doesn’t change anything. Sending the updated code:

/* Fill in information from Blynk Device Info here */

#define BLYNK_TEMPLATE_ID "TMPL4Br9ZPHq3"
#define BLYNK_TEMPLATE_NAME "Weather device"
#define BLYNK_AUTH_TOKEN "K6fzuHBkzN6pJ-N8-gUuphBpZ-FhrRvv"


#include <SPI.h>
#include <DHT.h>

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Muster";
char pass[] = "nxbn9777";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 19200 //default baudrate

ESP8266 wifi(&EspSerial);


// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht11(6,DHTTYPE);

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5)
void sendSensor()
{
  float t = dht11.readTemperature();
  float h = dht11.readHumidity();
  Serial.print("Current humidity = ");
  Serial.print(h);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(t); 
  Serial.println("C  ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.

  if (isnan(h) || isnan(t)) {
    Blynk.virtualWrite(V3, 1);
    return;
  }
  else {
    Blynk.virtualWrite(V3, 3);
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, h);
  Blynk.virtualWrite(V1, t);

}

void setup()
{
  // Debug console
  Serial.begin(9600);
 
  dht11.begin();
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass, "blynk.cloud", 80);

  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}

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

Do you mean in your serial monitor?

You shouldn’t be doing this…

Your code isn’t accessing the sensor again, it’s simply sending the stored values to Blynk.

You need to explain more.
Is this the web dashboard? If so then you’re probably looking at the template view not the device view.

If that’s not the issue then you need to share info about your datastreams and widgets.

Pete.

Yes, I am also printing out the values from sensor to Serial monitor to check if the sensor still operational and is able to do measurements. I am definitely checking the web dashboard in my device tab. Here are my datastreams:


and my web dashboard:

Here “DHT on” is used only to check if the values are not NaN on DHT, the other two are Label widgets connected to V0 and V1 datastreams

The return; at the end of this part of your if statement prevents the lines that follow it from being executed.

Pete.

Thank you so much for your help, Pete. I finally receive data on my web dashboard. Feel really stupid right now looking at this simple mistake. Again thanks.

1 Like