Blynk ESP8266 with multi DHT11 ---- Help to find problem

Hi everyone,

I’m looking to built a multi-sensor for home with ESP8266, DHT11 and blynk.
That’s my first project with Arduino-Blynk and I don’t find what is the fault in my prog.
I copy my prog here and wish someone can help me to find the problem.


//DHT11 And NodeMCU With Blynk
#define BLYNK_PRINT Serial
 
 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
 
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxx";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
 
#define DHTPIN 0          // D3
#define DHTPIN 1          // D4
#define DHTPIN 2          // D5
#define DHTPIN 3          // D6

// 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 0 (D3, DHTTYPE);
DHT 1 (D4, DHTTYPE);
DHT 2 (D5, DHTTYPE);
DHT 3 (D6, DHTTYPE);

BlynkTimer timer;
 
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h1) || isnan(t1)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, t1);
  Blynk.virtualWrite(V2, h1);

  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h2) || isnan(t2)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V3, t2);
  Blynk.virtualWrite(V4, h2);

  float h3 = dht3.readHumidity();
  float t3 = dht3.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h3) || isnan(t3)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, t3);
  Blynk.virtualWrite(V6, h3);

  float h4 = dht4.readHumidity();
  float t4 = dht4.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h4) || isnan(t4)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V7, t4);
  Blynk.virtualWrite(V8, h4);

  float h = dht4.readHumidity();
  float t = dht4.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, t1);
  Blynk.virtualWrite(V2, h1);
  
  Blynk.virtualWrite(V3, t2);
  Blynk.virtualWrite(V4, h2);
  
  Blynk.virtualWrite(V5, t3);
  Blynk.virtualWrite(V6, h3);
  
  Blynk.virtualWrite(V7, t4);
  Blynk.virtualWrite(V8, h4);
  
}
 
void setup()
{
  // Debug console
  Serial.begin(9600);
 
   Blynk.begin(auth, ssid, pass, IPAddress(192,168,15,200), 8080);
 
  dht1.begin();
  dht2.begin();
  dht3.begin();
  dht4.begin();
  
  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}
 
void loop()
{
  Blynk.run();
  timer.run();
}

Thank to help me, I’m sure I’m not so far to be good.

Pierre Paulus

@Pierre_Paulus Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

Hi Pete,

Thank for your advise. I’m new on arduino and it’s the first time I’m using community for help.

Pierre Paulus

Are you running Blynk Legacy on a local server?

There appears to be some pieces of code missing.

Pete.

The project work perfect with 1 DHT11 on blynk local server. But I want to put more of them.
And sorry for my bad English. I’m French.

Pierre

I’d suggest that you add some serial print commands to see what values you’re getting from each sensor.

Is this your sketch, or one you’ve found somewhere?

Pete.

I found a base sketch and want to add more probe on it.
I’ll add serial print to see live what wrong.

Thanks

Pierre

Get a basic sketch to work with multiple sensors, then implement it to Blynk.

But NEVER use a 1 Hz timer with DHT11! It’s a very slow sensor that needs about 1 second to get the reading done. During this time your sketch is halted, and nothing else happens. Then, when the reading is done, it jumps right back to do it again, and again, and again…

Trust me, you don’t need to know how much the humidity in your living room changes every second. :smiley: Every 5-10 min will do!