DHT11 two led simple circuit

Hello all,

I'm a bit baffled right now. I am trying to run a simple circuit on the UNO where a red LED turns on when the temperature gets too high, and a blue LED turns on when the humidity gets too high. However, only when the temp is too high does the red turn on. If both the temp and humidity are too high, both LEDs only flicker. If the temp is below threshold and the humidity is high, the blue LED only flickers, but it should be on. Code posted below:

/*
  ARBOR- Attempt 1 at prototype 15 temperature and humidity control.
*/

// include the EduIntro library
#include <EduIntro.h>

DHT11 dht11(A0); //creating the object sensor on digital pin 7

int C;   // temperature C readings are integers
float F; // temperature F readings are returned in float format
int H;   // humidity readings are integers

const int analogPin = A0;    // pin that the sensor is attached to
const int ledPinH = 9;      // pin that the LED for humidity is attached to
const int thresholdH = 70;  // threshold level for testing responsiveness for humidity sensor
const int ledPinT = 10;     // pin that the LED for temperature is attached to
const int thresholdT = 28;  // threshold level for testing responsiveness for temperature sensor

void setup()
{
  // initialize the LED pins as an outputs:
  pinMode(ledPinH, OUTPUT);
  pinMode(ledPinT, OUTPUT);
  // initialize serial communications at 9600 bps
  Serial.begin(9600);
}

void loop()
{
  // read the value coming from DHT11
  dht11.update();

  C = dht11.readCelsius();      // Reading the temperature in Celsius degrees and store in the C variable
  F = dht11.readFahrenheit();   // Reading the temperature in Fahrenheit degrees and store in the F variable
  H = dht11.readHumidity();     // Reading the humidity index
  
  // if statements to guide LED lighting
  if(H > thresholdH && C > thresholdT) 
    {
      digitalWrite(ledPinH, HIGH);
      digitalWrite(ledPinT, HIGH);
    } 
  if(H > thresholdH && C <= thresholdT)
    {
      digitalWrite(ledPinH, HIGH);
      digitalWrite(ledPinT, LOW);
    }
  if(H <= thresholdH && C > thresholdT)
    {
      digitalWrite(ledPinH, LOW);
      digitalWrite(ledPinT, HIGH);
    } else {
      digitalWrite(ledPinH, LOW);
      digitalWrite(ledPinT, LOW);
    }

  // Print the collected data in a row on the Serial Monitor
  Serial.print("H: ");
  Serial.print(H);
  Serial.print("\tC: ");
  Serial.print(C);
  Serial.print("\tF: ");
  Serial.println(F);

  delay(500);                  // Wait half second before getting another temperature/humidity reading

}

Unless the 3rd "if" is true, both leds go off in the "else" at the bottom.

I'd make that "else" a 4th "if" to explicitly handle the 4th possibility of H and C

Seems absurdly convoluted. :astonished:

  // if statements to guide LED lighting
  if (H > thresholdH) digitalWrite(ledPinH, HIGH);
    else digitalWrite(ledPinH, LOW);

  if (C > thresholdT) digitalWrite(ledPinT, HIGH);
    else digitalWrite(ledPinT, LOW);

Paul__B:
Seems absurdly convoluted. :astonished:

I though that too, but wondered if there was more to the OP's requirement than s/he stated, and that perhaps the combinations of Hs and Cs might have some as yet unstated importance. (Along the lines of "if it's hot and humid" do foo....)

Paul__B:
Seems absurdly convoluted. :astonished:

  // if statements to guide LED lighting

if (H > thresholdH) digitalWrite(ledPinH, HIGH);
    else digitalWrite(ledPinH, LOW);

if (C > thresholdT) digitalWrite(ledPinT, HIGH);
    else digitalWrite(ledPinT, LOW);

Agreed. I originally had the same code you posted here, but still with the same result. Since I am new to Arduino, I wondered if the IF statements were interfering with each other somehow, so I changed it. Still same issue with that code though. Seems that even when set to HIGH, the PWM is not putting out wide voltage waves (or however you say that)

This has no connection whatsoever with PWM. :astonished:

What is the serial output telling you at this time?

I think you need to review exactly what the specifications of those three data values from the DHT11 are.