DHT11 Sensor Used With LCD Display and LED Lights.
DHT11 Sensor Used With LCD Display and LED Lights.
#define DHTPIN
8 // Set the DHT Pin.
#define DHTTYPE DHT11 //
Set the DHT type.
const
int yellowLED = 9; // Adds a led light (in that case, it is yellow)
to pin 9.
const int blueLED = 10; // Adds a led light (in that
case, it is blue) to pin 10.
const int whiteLED = 11; // Adds a
led light (in that case, it is white) to pin 11.
void setup() {
lcd.begin(16,
2); // Initializes the interface to the LCD screen, and
specifies
the dimensions (width and height) of the display.
lcd.setCursor(0, 0); //
Set the cursor to column 0, line 0.
pinMode(blueLED, OUTPUT); //
Change to output the blue pin.
pinMode(yellowLED, OUTPUT); // Change
to output the yellow pin.
pinMode(whiteLED, OUTPUT); // Change to
output the white pin.
void loop() {
delay(500); //
Wait 0.5 seconds before updating the values.
float T = dht.readTemperature();
// Read temperature in Celsius. If you want the Temperature in Fahrenheit,
simply
add "true" between the parentheses ==> float T = dht.readTemperature(True);
if
(isnan(H) && isnan(T)) { // See if H (the Humidity variable) is NaN (Not
A Number) && (Logical AND) See if T (the Temperature variable) is NaN to show
error.
}
else if(T<22){ // If the temperature is smaller than
22C.
digitalWrite(blueLED, HIGH); // The blue led will turn on.
else if(T=22){ //
If the temperature is equal than 22C.
digitalWrite(whiteLED, HIGH); //
The white led will turn on.
digitalWrite(yellowLED, LOW); // The yellow
led will turn off.
digitalWrite(blueLED, LOW); // The blue led will
turn off.
}