Temperature and Humidity sensor with LED Lights
This project project the temperature and the humidity level and turn on the LED Light depending on the temperature.
Components and supplies
1
Alphanumeric LCD, 16 x 2
3
Resistor 330 ohm
1
DHT11 Temperature & Humidity Sensor (3 pins)
3
LED (generic)
30
Jumper wires (generic)
1
Breadboard (generic)
1
Arduino Mega 2560
Apps and platforms
1
Arduino IDE
Project description
Code
DHT11 Sensor used with LCD Display and LED Lights.
arduino
1/* Created by Ralph Nader on 1/10/19. 2 Copyright 2019 Ralph Nader. All rights reserved. 3 Made with for everyone. 4 Spread your knowledge. 5 If you have any error or question, email me at "ralph@driple.co". 6*/ 7#include <LiquidCrystal.h> // Include the LiquidCrystal library. 8#include "DHT.h" // Include the DHT library. 9 10#define DHTPIN 8 // Set the DHT Pin. 11#define DHTTYPE DHT11 // Set the DHT type. 12 13LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates a LiquidCrystal object. Parameters: (RS, Enable (E), d4, d5, d6, d7). 14DHT dht(DHTPIN, DHTTYPE); // Creates a DHT object. Parameters: (DHT Pin, DHT Type). 15 16const int yellowLED = 9; // Adds a led light (in that case, it is yellow) to pin 9. 17const int blueLED = 10; // Adds a led light (in that case, it is blue) to pin 10. 18const int whiteLED = 11; // Adds a led light (in that case, it is white) to pin 11. 19 20void setup() { 21 lcd.begin(16, 2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display. 22 lcd.setCursor(0, 0); // Set the cursor to column 0, line 0. 23 pinMode(blueLED, OUTPUT); // Change to output the blue pin. 24 pinMode(yellowLED, OUTPUT); // Change to output the yellow pin. 25 pinMode(whiteLED, OUTPUT); // Change to output the white pin. 26 27 dht.begin(); // Launch the DHT11 sensor. 28 digitalWrite(blueLED,LOW); // Turn off LED. 29 digitalWrite(yellowLED,LOW); // Turn off LED. 30 digitalWrite(whiteLED, LOW); // Turn off LED. 31 32 lcd.print("Temperature:"); // Print "Temperature:" on LCD Screen. 33 34 lcd.setCursor(0, 1); // Set the cursor to column 0, line 1. 35 lcd.print("Humidity :"); // Print "Humidity:" on LCD Screen. 36} 37 38void loop() { 39 delay(500); // Wait 0.5 seconds before updating the values. 40 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); 41 float H = dht.readHumidity(); // Read humidity in percentage. 42 43 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. 44 lcd.print("ERROR"); // Print error where there's the error. 45 return; // Repeat the process with each update (each second). 46 } 47 48 if(T>22){ // See if the temperature is bigger than 22C. 49 digitalWrite(yellowLED, HIGH); // The yellow led will turn on. 50 digitalWrite(blueLED, LOW); // The blue led will turn off. 51 digitalWrite(whiteLED, LOW); // The white led will turn off.s 52 53 } 54 else if(T<22){ // If the temperature is smaller than 22C. 55 digitalWrite(blueLED, HIGH); // The blue led will turn on. 56 digitalWrite(yellowLED, LOW); // The yellow led will turn off. 57 digitalWrite(whiteLED, LOW); // The white led will turn off. 58 } 59 60 else if(T=22){ // If the temperature is equal than 22C. 61 digitalWrite(whiteLED, HIGH); // The white led will turn on. 62 digitalWrite(yellowLED, LOW); // The yellow led will turn off. 63 digitalWrite(blueLED, LOW); // The blue led will turn off. 64 } 65 66 lcd.setCursor(12, 0); // Set the cursor to column 12, line 0. 67 lcd.print(T); // Print the temperature. 68 lcd.setCursor(12, 1); // Set the cursor to column 12, line 1. 69 lcd.print(H); // Print the humidity level. 70}
DHT11 Sensor used with LCD Display and LED Lights.
arduino
1/* Created by Ralph Nader on 1/10/19. 2 Copyright 2019 Ralph Nader. 3 All rights reserved. 4 Made with for everyone. 5 Spread your knowledge. 6 7 If you have any error or question, email me at "ralph@driple.co". 8*/ 9#include 10 <LiquidCrystal.h> // Include the LiquidCrystal library. 11#include 12 "DHT.h" // Include the DHT library. 13 14#define DHTPIN 15 8 // Set the DHT Pin. 16#define DHTTYPE DHT11 // 17 Set the DHT type. 18 19LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates a LiquidCrystal 20 object. Parameters: (RS, Enable (E), d4, d5, d6, d7). 21DHT dht(DHTPIN, DHTTYPE); 22 // Creates a DHT object. Parameters: (DHT Pin, DHT Type). 23 24const 25 int yellowLED = 9; // Adds a led light (in that case, it is yellow) 26 to pin 9. 27const int blueLED = 10; // Adds a led light (in that 28 case, it is blue) to pin 10. 29const int whiteLED = 11; // Adds a 30 led light (in that case, it is white) to pin 11. 31 32void setup() { 33 lcd.begin(16, 34 2); // Initializes the interface to the LCD screen, and specifies 35 the dimensions (width and height) of the display. 36 lcd.setCursor(0, 0); // 37 Set the cursor to column 0, line 0. 38 pinMode(blueLED, OUTPUT); // 39 Change to output the blue pin. 40 pinMode(yellowLED, OUTPUT); // Change 41 to output the yellow pin. 42 pinMode(whiteLED, OUTPUT); // Change to 43 output the white pin. 44 45 dht.begin(); // Launch the 46 DHT11 sensor. 47 digitalWrite(blueLED,LOW); // Turn off LED. 48 digitalWrite(yellowLED,LOW); 49 // Turn off LED. 50 digitalWrite(whiteLED, LOW); // Turn off 51 LED. 52 53 lcd.print("Temperature:"); // Print "Temperature:" on 54 LCD Screen. 55 56 lcd.setCursor(0, 1); // Set the cursor to 57 column 0, line 1. 58 lcd.print("Humidity :"); // Print "Humidity:" 59 on LCD Screen. 60} 61 62void loop() { 63 delay(500); // 64 Wait 0.5 seconds before updating the values. 65 float T = dht.readTemperature(); 66 // Read temperature in Celsius. If you want the Temperature in Fahrenheit, simply 67 add "true" between the parentheses ==> float T = dht.readTemperature(True); 68 69 float H = dht.readHumidity(); // Read humidity in percentage. 70 71 if 72 (isnan(H) && isnan(T)) { // See if H (the Humidity variable) is NaN (Not 73 A Number) && (Logical AND) See if T (the Temperature variable) is NaN to show error. 74 75 lcd.print("ERROR"); // Print error where there's the error. 76 77 return; // Repeat the process with each update (each 78 second). 79 } 80 81 if(T>22){ // See if the temperature 82 is bigger than 22C. 83 digitalWrite(yellowLED, HIGH); // The yellow led will 84 turn on. 85 digitalWrite(blueLED, LOW); // The blue led will turn off. 86 87 digitalWrite(whiteLED, LOW); // The white led will turn off.s 88 89 90 } 91 else if(T<22){ // If the temperature is smaller than 92 22C. 93 digitalWrite(blueLED, HIGH); // The blue led will turn on. 94 95 digitalWrite(yellowLED, LOW); // The yellow led will turn off. 96 digitalWrite(whiteLED, 97 LOW); // The white led will turn off. 98 } 99 100 else if(T=22){ // 101 If the temperature is equal than 22C. 102 digitalWrite(whiteLED, HIGH); // 103 The white led will turn on. 104 digitalWrite(yellowLED, LOW); // The yellow 105 led will turn off. 106 digitalWrite(blueLED, LOW); // The blue led will 107 turn off. 108 } 109 110 lcd.setCursor(12, 0); // Set the cursor 111 to column 12, line 0. 112 lcd.print(T); // Print the temperature. 113 114 lcd.setCursor(12, 1); // Set the cursor to column 12, line 1. 115 116 lcd.print(H); // Print the humidity level. 117}
Downloadable files
DHT11 with LCD and LED Light
DHT11 with LCD and LED Light

Comments
Only logged in users can leave comments