How to declare and use various DHT22 sensors

Hello friends, thanks in advance for the help. I would like to know if I am correctly declaring the initial variables and commands in the script. Since it’s perfect for a sensor, but I want to see if I can add several to it, but it doesn’t transmit any. I am doing something wrong?

First of all I add details…
• Hardware model + communication type: Nodemcu V3 + DHT22
• Android and windows
• Blynk server
• Blynk Library version: last

#define DHTPIN 5          // el pin digital al que está conectado el sensor 1
#define DHT_2PIN 4          // el pin digital al que está conectado el sensor 2
#define DHT_3PIN 0          // el pin digital al que está conectado el sensor 3
#define DHT_4PIN 2          // el pin digital al que está conectado el sensor 4
#define DHT_5PIN 14          // el pin digital al que está conectado el sensor 5
#define DHT_6PIN 12          // el pin digital al que está conectado el sensor 6
#define DHT_7PIN 13          // el pin digital al que está conectado el sensor 7
#define DHTTYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato) 
#define DHT_2TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
#define DHT_3TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
#define DHT_4TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
#define DHT_5TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
#define DHT_6TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
#define DHT_7TYPE DHT22     // DHT 22 (dht11 si es el sensor mas varato)
DHT dht(DHTPIN, DHTTYPE); //declara la variable para el sensor 1
DHT dht_2(DHT_2PIN, DHT_2TYPE); //declara la variable para el sensor 2
DHT dht_3(DHT_3PIN, DHT_3TYPE); //declara la variable para el sensor 3
DHT dht_4(DHT_4PIN, DHT_4TYPE); //declara la variable para el sensor 4
DHT dht_5(DHT_5PIN, DHT_5TYPE); //declara la variable para el sensor 5
DHT dht_6(DHT_6PIN, DHT_6TYPE); //declara la variable para el sensor 6
DHT dht_7(DHT_7PIN, DHT_7TYPE); //declara la variable para el sensor 7

and more script...-----------------------------------------------------------------

void sendSensor(){
		float hum = dht.readHumidity(); 
		float temp = dht.readTemperature(); 
			if (isnan(hum) || isnan(temp)) {
				Serial.println("Fallo en la lectura del primer sensor!");
			return;
	}
		float hum_2 = dht_2.readHumidity(); 
		float temp_2 = dht_2.readTemperature(); 
			if (isnan(hum_2) || isnan(temp_2)) {
				Serial.println("Fallo en la lectura del segundo sensor!");
			return;
	}
		float hum_3 = dht_3.readHumidity(); 
		float temp_3 = dht_3.readTemperature(); 
			if (isnan(hum_3) || isnan(temp_3)) {
				Serial.println("Fallo en la lectura del tercer sensor!");
			return;
	}
		float hum_4 = dht_4.readHumidity(); 
		float temp_4 = dht_4.readTemperature(); 
			if (isnan(hum_4) || isnan(temp_4)) {
				Serial.println("Fallo en la lectura del cuarto sensor!");
			return;
	}
		float hum_5 = dht_5.readHumidity(); 
		float temp_5 = dht_5.readTemperature();
			if (isnan(hum_5) || isnan(temp_5)) {
				Serial.println("Fallo en la lectura del quinto sensor!");
			return;
	}
		float hum_6 = dht_6.readHumidity(); 
		float temp_6 = dht_6.readTemperature(); 
			if (isnan(hum_6) || isnan(temp_6)) {
				Serial.println("Fallo en la lectura del sexto sensor!");
			return;
	}
		float hum_7 = dht_7.readHumidity(); 
		float temp_7 = dht_7.readTemperature(); 
			if (isnan(hum_7) || isnan(temp_7)) {
				Serial.println("Fallo en la lectura del septimo sensor!");
			return;
	}
                  Blynk.virtualWrite(V1, hum);
                  Blynk.virtualWrite(V0, temp);
                  Serial.print("Temperatura : ");
                  Serial.print(temp);
                  Serial.print("  Humedad : ");
                  Serial.println(hum);
                  Blynk.virtualWrite(V3, hum_2);
                  Blynk.virtualWrite(V2, temp_2);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_2);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_2);
                  Blynk.virtualWrite(V5, hum_3);
                  Blynk.virtualWrite(V4, temp_3);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_3);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_3);
                  Blynk.virtualWrite(V7, hum_4);
                  Blynk.virtualWrite(V6, temp_4);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_4);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_4);
                  Blynk.virtualWrite(V9, hum_5);
                  Blynk.virtualWrite(V8, temp_5);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_5);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_5);
                  Blynk.virtualWrite(V11, hum_6);
                  Blynk.virtualWrite(V10, temp_6);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_6);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_6);
                  Blynk.virtualWrite(V13, hum_7);
                  Blynk.virtualWrite(V12, temp_7);
                  Serial.print("Temperatura : ");
                  Serial.print(temp_7);
                  Serial.print("  Humedad : ");
                  Serial.println(hum_7);
}

and more...-----------------------------------------------------------------

 Blynk.begin(auth, ssid, pass);
             //ejecutamos el dht
              dht.begin();
              dht_2.begin();
              dht_3.begin();
              dht_4.begin();
              dht_5.begin();
              dht_6.begin();
              dht_7.begin();
              //tiempo de lectura del sensor
            timer.setInterval(3000L, sendSensor);
            }

//ejecucion de funciones del programa
void loop(){
            Blynk.run();
            timer.run();
           }

I hope you can help me…

Is this the whole sketch ?
If no, post your whole sketch please.

also, are you using blynk IOT or legacy ?

Blynk 2.0

the script…

#define BLYNK_TEMPLATE_ID "blablabla"
#define BLYNK_DEVICE_NAME "blablabla"
#define BLYNK_AUTH_TOKEN "blablabla"

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h >
#include <WiFiManager.h>
#include <Ticker.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h> 
Ticker ticker;
byte pinLed = D4;
void parpadeoLed(){
  byte estado = digitalRead(pinLed);
  digitalWrite(pinLed, !estado);
}
char auth[] = BLYNK_AUTH_TOKEN; 
char ssid[] = "";  
char pass[] = "";  
#define DHTPIN 2      
#define DHTTYPE DHT22     
#define DHTPIN2 5         
DHT dht(DHTPIN, DHTTYPE); 
DHT dht2(DHTPIN2, DHTTYPE);
BlynkTimer timer; 
float hum; 
float temp;
float hum2; 
float temp2;
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h >
#include <WiFiManager.h>

void sendSensor(){
                  float hum = dht.readHumidity(); 
                  float temp = dht.readTemperature(); 
                
                  if (isnan(hum) || isnan(temp)) {
                                                  Serial.println("Fallo en la lectura del sensor!");
                                                  return;
                                                 }
                  Blynk.virtualWrite(V0, temp);
                  Blynk.virtualWrite(V1, hum);
                  Serial.print("Temperatura : ");
                  Serial.print(temp);
                  Serial.print("  Humedad : ");
                  Serial.println(hum);
                  float hum2 = dht2.readHumidity();
                  float temp2 = dht2.readTemperature();
                  if (isnan(hum2) || isnan(temp2)) {
                                                  Serial.println("Fallo en la lectura del sensor!");
                                                  return;
                                                 }
                  Blynk.virtualWrite(V2, temp2);
                  Blynk.virtualWrite(V3, hum2);
                  Serial.print("Temperatura : ");
                  Serial.print(temp2);
                  Serial.print("  Humedad : ");
                  Serial.println(hum2);

                  
                                                                              }                                   
                              

void setup(){  
  Serial.begin(115200);
  pinMode(pinLed, OUTPUT);
  ticker.attach(0.2, parpadeoLed);
  WiFiManager wifiManager;
  wifiManager.resetSettings();
  if(!wifiManager.autoConnect("my_wifi")){
                                              Serial.println("Fallo en la conexión (timeout)");
                                              ESP.reset();
                                              delay(1000);
                                              }
 
  Serial.println("is conected");
 
  ticker.detach();
  digitalWrite(pinLed, HIGH);
             Blynk.begin(auth, ssid, pass);
              dht.begin();
              dht2.begin();
            timer.setInterval(3000L, sendSensor);
            }
void loop(){
            Blynk.run();
            timer.run();
           }

Please post what you see on your serial monitor from start .

I’d suggest increasing the timer to 10 seconds for example instead of 3 seconds.

He use DTH22, so it is 1 Hz sampling rate .

the sampling rate of the DHT22 is 0.5Hz (one reading every two seconds). also, he’s using multiple DHT22 sensors.

Okay, so now go back and tidy- up your previous posts so that we have one set of code, one serial monitor output, and some information about what is being displayed in the app/web console fot each datastream.

Pete.

CODE

#define BLYNK_TEMPLATE_ID "XXXXXXXXX"
#define BLYNK_DEVICE_NAME "XXXXXXXXXXXX"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXX"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <Ticker.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
Ticker ticker;
byte pinLed = D4;
void parpadeoLed(){
  // Cambiar de estado el LED
  byte estado = digitalRead(pinLed);
  digitalWrite(pinLed, !estado);
  }
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
#define DHTPIN 2 //A SENSOR
#define DHTPIN2 5 //B SENSOR
#define DHTTYPE DHT22
#define DHTTYPE2 DHT22
DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE2);
BlynkTimer timer;
float hum;
float temp;
float hum2;
float temp2;
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h >
#include <WiFiManager.h>
void sendSensor(){
                  float hum = dht.readHumidity();
                  float temp = dht.readTemperature();
                  if (isnan(hum) || isnan(temp)) {
                                                  Serial.println("A SENSOR NOT FOUND ");
                                                  return;
                                                 }
                  Blynk.virtualWrite(V0, temp);
                  Blynk.virtualWrite(V1, hum);
                  Serial.print("  A SENSOR TEMPERATURE: ");
                  Serial.print(temp);
                  Serial.print("  A SENSOR HUMIDITY: ");
                  Serial.println(hum);
                  float hum2 = dht2.readHumidity();
                  float temp2 = dht2.readTemperature();
                  if (isnan(hum2) || isnan(temp2)) {
                                                  Serial.println("B SENSOR NOT FOUND");
                                                  return;
                                                 }
                  Blynk.virtualWrite(V2, temp2);
                  Blynk.virtualWrite(V3, hum2);
                  Serial.print("  B SENSOR TEMPERATURE: ");
                  Serial.print(temp2);
                  Serial.print(" B SENSOR HUMIDITY: ");
                  Serial.println(hum2);
                  }
void setup(){   
      Serial.begin(115200);
      pinMode(pinLed, OUTPUT);
      ticker.attach(0.2, parpadeoLed);
      WiFiManager wifiManager;
      //discomment for reset wifi data
      //wifiManager.resetSettings();
      if(!wifiManager.autoConnect("my_wifi")){
                                              Serial.println("bad conexion (timeout)");
                                              ESP.reset();
                                              delay(1000);
                  }
 
  Serial.println("It is connected");
  ticker.detach();
  digitalWrite(pinLed, HIGH);
             Blynk.begin(auth, ssid, pass);
             //ejecutamos el dht
              dht.begin();
              dht2.begin();
            timer.setInterval(1000L, sendSensor);
            }
            
void loop(){
            Blynk.run();
            timer.run();
           }

SERIAL MONITOR OUTPUT

Temperatura SENSOR A : 21.10 Humedad SENSOR A: 65.00
*wm:[1] connectTimeout not set, ESP waitForConnectResult…
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[2] Connected in 1839 ms
*wm:[1] STA IP Address: 192.168.1.101
It is connected
[1915] Connecting to
[1917] Connected to WiFi
[1919] IP: 192.168.1.101
[1921]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v1.0.1 on ESP8266

[1934] Connecting to blynk.cloud:80
[2428] Ready (ping: 176ms).
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 64.90
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00
B SENSOR NOT FOUND
A SENSOR TEMPERATURE: 21.10 A SENSOR HUMIDITY: 65.00

I think that was all you asked me for. From that code came those serial monitor data, from a device configured with those values ​​in the sensors.
thanks Pete

Have you tried increasing the timer ? try 7000L for example.

I assume you have inverted the sensors to be sure it is not a hardware failure?

No, I’d asked you to de-clutter the topic by either editing your previous posts to replace the code, serial outputs screenshots etch with correctly modified ones, or deleting them.
I’ve now done that for you.

The latest serial output cannot have been produced from the code you posted, because of this…

I assume that’s you being sloppy and not clearing your serial output before running the new sketch?

You are doing something odd with GPIO2 (Pin D4) ….

The same pin is being used for your LED and your first DHT sensor (Sensor A).

I’m not sure why Sensor A is working and Sensor B isn’t, but I’d suggest changing the pin that Sensor A is connected to and see if it still works.
It’s a really good idea to always use proper GPIO assignments in your code, rather than the “D” aliases as it makes pin conflicts much easier to spot.

Pete.