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
}