user70358: the point of my code is to turn on a LED when the humidity level reaches a certain amount. However it reads the amount of humidity but the LED is not turning on. Why isn't it working??
#include <SimpleDHT.h>

// for DHT11,
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11;


void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  }

void loop() {
  // start working...
  Serial.println("=================================");
  Serial.println("Sample DHT11...");

  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;

  if (humidity > 70 ) {
     digitalWrite(9, HIGH);
  }
  else if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
    return;
  }

  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" H");

  // DHT11 sampling rate is 1HZ.
  delay(1500);
}



user53266: Your code does not work because in fact error statement reads the value of temperature and humidity sensor.
You set the humidity and temperature variables to 0. If statement compares this variables to 70, before actually reading sensor data.
I haven't tested but this should work.
#include <SimpleDHT.h>

int pinDHT11 = 2;
SimpleDHT11 dht11;

void setup()
{
    Serial.begin(9600);
    pinMode(9, OUTPUT);
}

void loop()
{
    // start working...
    Serial.println("=================================");
    Serial.println("Sample DHT11...");

    // read without samples.
    byte temperature = 0;
    byte humidity = 0;

    int err = SimpleDHTErrSuccess;
    if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL))
        != SimpleDHTErrSuccess)
    {
        Serial.print("Read DHT11 failed, err=");
        Serial.println(err);
        delay(1000);
        return;
    }

    Serial.print("Sample OK: ");
    Serial.print((int)temperature);
    Serial.print(" *C, ");
    Serial.print((int)humidity);
    Serial.println(" H");

    if (humidity > 70 )
    {
        Serial.println("Humidity is above 70%");
        digitalWrite(9, HIGH);
    }
    else
    {
        Serial.println("Humidity is below 70%");
    }
    // DHT11 sampling rate is 1HZ.
    delay(1500);
}


70358: <p>the point of my code is to turn on a LED when the humidity level reaches a certain amount. However it reads the amount of humidity but the LED is not turning on. Why isn't it working??</p>
<pre><code>#include &lt;SimpleDHT.h&gt;

// for DHT11,
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11;


void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  }

void loop() {
  // start working...
  Serial.println(&quot;=================================&quot;);
  Serial.println(&quot;Sample DHT11...&quot;);

  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;

  if (humidity &gt; 70 ) {
     digitalWrite(9, HIGH);
  }
  else if ((err = dht11.read(pinDHT11, &amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print(&quot;Read DHT11 failed, err=&quot;); Serial.println(err);delay(1000);
    return;
  }

  Serial.print(&quot;Sample OK: &quot;);
  Serial.print((int)temperature); Serial.print(&quot; *C, &quot;);
  Serial.print((int)humidity); Serial.println(&quot; H&quot;);

  // DHT11 sampling rate is 1HZ.
  delay(1500);
}

</code></pre>
 53266: <p>Your code does not work because in fact error statement reads the value of temperature and humidity sensor.</p>
<p>You set the <code>humidity</code> and <code>temperature</code> variables to 0. If statement compares this variables to 70, before actually reading sensor data.</p>
<p>I haven't tested but this should work.</p>
<pre><code>#include &lt;SimpleDHT.h&gt;

int pinDHT11 = 2;
SimpleDHT11 dht11;

void setup()
{
    Serial.begin(9600);
    pinMode(9, OUTPUT);
}

void loop()
{
    // start working...
    Serial.println(&quot;=================================&quot;);
    Serial.println(&quot;Sample DHT11...&quot;);

    // read without samples.
    byte temperature = 0;
    byte humidity = 0;

    int err = SimpleDHTErrSuccess;
    if ((err = dht11.read(pinDHT11, &amp;temperature, &amp;humidity, NULL))
        != SimpleDHTErrSuccess)
    {
        Serial.print(&quot;Read DHT11 failed, err=&quot;);
        Serial.println(err);
        delay(1000);
        return;
    }

    Serial.print(&quot;Sample OK: &quot;);
    Serial.print((int)temperature);
    Serial.print(&quot; *C, &quot;);
    Serial.print((int)humidity);
    Serial.println(&quot; H&quot;);

    if (humidity &gt; 70 )
    {
        Serial.println(&quot;Humidity is above 70%&quot;);
        digitalWrite(9, HIGH);
    }
    else
    {
        Serial.println(&quot;Humidity is below 70%&quot;);
    }
    // DHT11 sampling rate is 1HZ.
    delay(1500);
}
</code></pre>
