Ich möchte gern mehrere Sensoren über die Virtuellen Pins auslesen, mit einem Sensor Funktioniert es ab 2 Stück nicht mehr


  App project setup:
    Value Display widget attached to V5
    Value Display widget attached to V6
 *************************************************************/

/* Comment this out to disable prints and save space */
#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[] = "";

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

#define DHTPIN 2          // What digital pin we're connected to
#define DHTPIN2 4         
#define DHTPIN3 2
// 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 dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, 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 h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  float h2 = dht2.readHumidity();     
  float t2 = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  
  float h3 = dht3.readHumidity();   
  float t3 = dht3.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  if (isnan(h2) || isnan(t2)) {       
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

   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, h);
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V7, h2);
  Blynk.virtualWrite(V8, t2);
  Blynk.virtualWrite(V9, h3);
  Blynk.virtualWrite(V10, t3);

}

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin
  //Blynk.begin

  dht.begin();

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

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

Please repost code, properly formatted as instructed, thanks. - Moderator

Blynk - FTFC

Also include detailed information about your issue, what you are trying to do and what you have tried so far. Be aware that we try to help you learn about Blynk… but we are not code mechanics, nor do we teach programming.

mein deutsch is sehr begrenzt aber die DHTPIN und DHTPIN3 benutze den gleichen Pin (2), das kann nicht richtig funktionieren!

Hallo, ich habe es geändert in Pin 5 aber es läuft dennoch nicht…

Hast du auch jeden Pin einzeln getestet?

Hey, bin leider erst jetzt zum testen gekommen, also wenn ich die anderen auskommentiere und den 2 oder 3 laufen lassen will, das geht auch nicht, der erste ist der einzige der läuft (Pin 2)

ok und was bedeutet: “Funktioniere nicht mehr”, kannst du eine Beschreibung geben? Oder besser: Serial.print output.

Oh, und das nähert sich meiner Sprachgrenze, so wenn möglich bitte auf Englisch! (oder Niederländisch :smiley: ).

Hallo, der einzige Pin der funktioniert ist Pin 2 ( Original Sketch von Blynk)
Mit englisch kann ich leider nicht dienen…

My english is Not The yellow from The egg :joy:

Ich nehme 'mal an, dass der zweite und dritte Sensor alleine laufen, richtig?

Das Problem ist vermutlich die Häufigkeit, mit der die Sensoren abgefragt werden.

Im Datenblatt steht “Collecting period should be : >2 second.”
Eine Sekunde geht wohl auch noch, aber nicht wenn “sendSensor” einmal pro Sekunden aufgerufen wird
und damit drei Sensoren abgefragt werden sollen.
Das würde ich 'mal mit timer.setInterval(10000L, sendSensor); probieren.

Das verstehe ich. Was ich meine ist: Was passiert im Detail?

@IBK:
Dank fürs einsteigen, es ist swcher fur mich dieses Gesprach auf Deutsch zu fuhren.

Hallo, ich hatte den ersten und den dritten Sensor auskommentiert, so das nur der zweite hätte laufen sollen, dies funktionierte leider nicht, werde es heute Abend aber noch mal testen um sicher zu gehen, danke für den Tipp, das probiere ich auch gleich aus!
Und melde mich nochmal!!

Was genau möchtest du wissen, was im Detail passiert?
Ich verstehe die Frage nicht genau, entschuldige bitte

Du must jetzt Google Translate verwenden, Ich mache weiter auf Englisch.

What I mean is:

  • does the unit stop working completely?
  • do the lights in your house go out when you connect more than one sensor
  • does the app stop working
  • are you getting one correct value and two incorrect values?
  • or are all values not working
  • does the unit no longer connect when you use more than 1 sensor
  • does the serial log do show the correct values but the app not/
  • are you using serial.println at all?
  • what values do you get?
  • Have you tried/tested each seperate sensor on the same working pin?
  • Have you tried testing the working sensor on the other pins?
  • does the app eat your phone when you connect more than 1 sensors

‘it does not work’ can literally mean a plethora of things and its (nigh) impossible to solve an issue solely based on ‘it does not work’. Describe the issue in detail and exactly what you did and what the result was and HOW you came to the conclusion: ‘it does not work’.

@ Tom1:

One more thing:
In the setup() I only see “dht.begin();” but what is missing is “dht2.begin();” and “dht3.begin();”
You need to initialize all three instances …

1 Like

nice catch!

magic it works, you are the best, have a thousand thanks !!!

Hallo, ich habe schon wieder eine Frage, ihr habt mir bei dem Sketch mit den 3 Sensoren schon so super geholfen, ich würde jetzt gerne über den ersten Sensor, 2 Relais steuern, das eine abhängig von der Luftfeuchtigkeit und das andere abhängig von der Temperatur schalten, weiß aber nich wie ich dieses realisieren soll…
Könntet ihr mir dabei nochmal helfen?

@Tom1: Ich würde das einfach in die sendSensor() Funktion einbauen. Z.B. so:

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  [...]

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    
    digitalWrite(RelaisH,LOW);
    
    return;
  }
  else
  {
    if(h > hMax) {
       digitalWrite(RelaisH,HIGH);
    }
    if(h < hMin) {
      digitalWrite(RelaisH,LOW);
    } 

    [...]    
  }

[...]
}

hMax, hMin, RelaisH etc. wird einfach z.B. per #define festgelegt.

Das hat jetzt aber nix mit Blynk zu tun … :wink:


/* Comment this out to disable prints and save space */
#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[] = "";

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

#define DHTPIN 2          // What digital pin we're connected to
#define DHTPIN2 4          // Hier die Pin Nummer eintragen wo der Sensor angeschlossen ist
#define DHTPIN3 5
#define hMax
#define hMin 
#define RelaisH 3

// 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 dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, 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 h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  float h2 = dht2.readHumidity();    // Lesen der Luftfeuchtigkeit und speichern in die Variable h
  float t2 = dht2.readTemperature(); // Lesen der Temperatur in °C und speichern in die Variable t
  
  float h3 = dht3.readHumidity();    // Lesen der Luftfeuchtigkeit und speichern in die Variable h
  float t3 = dht3.readTemperature(); // Lesen der Temperatur in °C und speichern in die Variable t

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  digitalWrite(RelaisH,LOW);
    return;
  }
else
  {
  if(h > h89) {
    digitalWrite(RelaisH,HIGH);
  }  
  if(h < h75) {
    digitalWrite(RelaisH,LOW);
  }
  if (isnan(h2) || isnan(t2)) {       
    Serial.println("Fehler beim auslesen des 1 Sensors!");
    return;
  }

   if (isnan(h3) || isnan(t3)) {       
    Serial.println("Fehler beim auslesen des 1 Sensors!");
    return;
  }
  
  
  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
 Blynk.virtualWrite(V7, h2);
  Blynk.virtualWrite(V8, t2);
 Blynk.virtualWrite(V9, h3);
  Blynk.virtualWrite(V10, t3);

}

void setup()



{
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

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

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

@Tom1: Das bekommt man so nicht compeliert :frowning_face:
Das hat 'mal wieder nix mit Blynk zu tun …:wink:

Eher wohl so:

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

#define DHTPIN   2  
#define DHTPIN2  4 
#define DHTPIN3  5

#define hMax    89 // !!
#define hMin    75 // !!
#define RelaisH  3

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);

BlynkTimer timer;

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); 

  float h2 = dht2.readHumidity();  
  float t2 = dht2.readTemperature();
  
  float h3 = dht3.readHumidity();    
  float t3 = dht3.readTemperature();

  if (isnan(h) || isnan(t)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    digitalWrite(RelaisH,LOW);
    return;
  }
  else
  {
    if(h > hMax) 
    {
      digitalWrite(RelaisH,HIGH);
    }  
    if(h < hMin) 
    {
      digitalWrite(RelaisH,LOW);
    }
  }
 
  if (isnan(h2) || isnan(t2)) 
  {       
    Serial.println("Fehler beim auslesen des 1 Sensors!");
    return;
  }

  if (isnan(h3) || isnan(t3)) 
  {       
    Serial.println("Fehler beim auslesen des 1 Sensors!");
    return;
  }

  Blynk.virtualWrite( V5, h);
  Blynk.virtualWrite( V6, t);
  Blynk.virtualWrite( V7, h2);
  Blynk.virtualWrite( V8, t2);
  Blynk.virtualWrite( V9, h3);
  Blynk.virtualWrite(V10, t3);
}

void setup()
{
  pinMode(RelaisH, OUTPUT);   // !!
  
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
 
  dht.begin();
  dht2.begin();
  dht3.begin();
 
  timer.setInterval(5000L, sendSensor);
}

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