DHT11

Hi Togheter,

i dont understand a programcode. Normally should put the arduino the relay on by a humidity over 55%. But the arduino doing nothing. Why? Can somebody help me, i dont know what i done wrong. Many Thanks!!!

DHT_Test2.ino (1.66 KB)

The contents of DHT_Test2.ino attached above:

#include "DHT.h"
// #include "dht.h"

#define DHT1PIN 2
#define DHT2PIN 3

#define DHT1TYPE DHT11
#define DHT2TYPE DHT11

DHT dht1 (DHT1PIN, DHT1TYPE);
DHT dht2 (DHT2PIN, DHT2TYPE);

void setup ()
{
  Serial.begin(9600);
  Serial.println ("KIMAG.DE - Luftfeuchtigkeitskontrollprogramm HUMIDITY V.1.0.1.");
  Serial.println ("--------------------------------------------------------------");
  Serial.println ("(C) 2016 by Michael Kuntze, s.c.E. // KIMAG.DE - Engineering");
  Serial.println ();

  delay (1000);

  dht1.begin();
  dht2.begin();

  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (8, LOW);
  pinMode (9, LOW);
}

void loop ()

{
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature();

  if (isnan(t1) || isnan(h1))
    {
      Serial.println("Failed to read from DHT #1");
    }
    else
    {
      Serial.print("Humidity 1: ");
      Serial.print(h1);     
      Serial.print(" %\t");
      Serial.print("Temperature 1: ");
      Serial.print(t1);
      Serial.println(" *C");
    }

    if ((t1) > 20);
    {
      digitalWrite (8, HIGH);
    }
    if ((t1) < 22);
    {
      digitalWrite (8, LOW);
    }

 // delay (2500);

  if (isnan(t2) || isnan(h2))
    {
      Serial.println("Failed to read from DHT #2");
    }
    else
    {
      Serial.print("Humidity 2: ");
      Serial.print(h2);
      Serial.print(" %\t");
      Serial.print("Temperature 3: ");
      Serial.print(t2);
      Serial.println(" *C");
    }

    if (h2>55);
    {
      digitalWrite (9, HIGH);
    }
    if (h2 < 55);
    {
      digitalWrite (9, LOW);
    }

    delay(2500);
    
  Serial.println();
}

Remove the semicolon from all the if() statements.

In the future please post your code using code tags(</> button).

Why do you have parentheses around t1

    if ((t1) < 22);

but not around h2?

    if (h2>55);

This was just a test, but with () and also without () is the "if" not working. The serialprint yes, shows alsp correct data but no reaction of the if for relay by temperatur and humidity.

Have you tested the relay hardware by running a simple test sketch that only switches the relays on and off?

Yes, the relays are working fine. The problem is just, that the relay dont get on by humdity >55% and off by <55%.

They are still on or still off.... The arduino isnt interessted on the data from DHT11. I cant understand. Also the semicolons i removed by the "ifs"... the same, isnt working.

  if (h2 > 55) digitalWrite (dehumidifier2, LOW);
  if (h2 > 60) digitalWrite (dehumidifier2, LOW);
  
  if (h2 < 54) digitalWrite (dehumidifier2, HIGH);
  if (h2 < 50) digitalWrite (dehumidifier2, HIGH);

This was the solution. Now is working. Thank at all for your help!