Project tutorial
Temperature and Humidity sensor with LED Lights

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.

  • 2 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

Hello. I've decided to create this project for the engineering class in university.

Things got exciting once I've added more code and linked it to the Air Conditioner.

The published project is to see the current temperature and humidity, and turn on led lights depending on the current temperature. It is not complex at all, but fun to make.

Hope you'll enjoy it as much as I did.

Code

DHT11 Sensor used with LCD Display and LED Lights.Arduino
/* Created by Ralph Nader on 1/10/19.
   Copyright  2019 Ralph Nader. All rights reserved.
   Made with  for everyone.
   Spread your knowledge.
   If you have any error or question, email me at "ralph@driple.co".
*/
#include <LiquidCrystal.h>             // Include the LiquidCrystal library.
#include "DHT.h"                       // Include the DHT library.

#define DHTPIN 8                       // Set the DHT Pin.
#define DHTTYPE DHT11                  // Set the DHT type.

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);   // Creates a LiquidCrystal object. Parameters: (RS, Enable (E), d4, d5, d6, d7).
DHT dht(DHTPIN, DHTTYPE);              // Creates a DHT object. Parameters: (DHT Pin, 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.

  dht.begin();                         // Launch the DHT11 sensor.
  digitalWrite(blueLED,LOW);           // Turn off LED.
  digitalWrite(yellowLED,LOW);         // Turn off LED.
  digitalWrite(whiteLED, LOW);         // Turn off LED.

  lcd.print("Temperature:");           // Print "Temperature:" on LCD Screen.
  
  lcd.setCursor(0, 1);                 // Set the cursor to column 0, line 1.
  lcd.print("Humidity   :");           // Print "Humidity:" on LCD Screen.
}

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);
  float H = dht.readHumidity();       // Read humidity in percentage.

  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. 
    lcd.print("ERROR");               // Print error where there's the error.
    return;                           // Repeat the process with each update (each second).
  }

  if(T>22){                           // See if the temperature is bigger than 22C.
    digitalWrite(yellowLED, HIGH);    // The yellow led will turn on.
    digitalWrite(blueLED, LOW);       // The blue led will turn off.
    digitalWrite(whiteLED, LOW);      // The white led will turn off.s
    
  }
  else if(T<22){                      // If the temperature is smaller than 22C.
    digitalWrite(blueLED, HIGH);      // The blue led will turn on.
    digitalWrite(yellowLED, LOW);     // The yellow led will turn off.
    digitalWrite(whiteLED, LOW);      // The white led will turn off.
  }

  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.
  }

  lcd.setCursor(12, 0);               // Set the cursor to column 12, line 0.
  lcd.print(T);                       // Print the temperature.
  lcd.setCursor(12, 1);               // Set the cursor to column 12, line 1.
  lcd.print(H);                       // Print the humidity level.
}

Schematics

DHT11 with LCD and LED Light
Dht11 project 5tckt55q7e

Comments

Similar projects you might like

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 21,430 views
  • 6 comments
  • 40 respects

Temperature and Humidity Logger Per Hour

Project tutorial by lefteris1993

  • 2,535 views
  • 0 comments
  • 13 respects

Beautifully Finished Humidity and Temperature Sensor

Project tutorial by Wicked Makers

  • 19,795 views
  • 22 comments
  • 144 respects

Arduino Temperature - Humidity - Rain Sensor

Project showcase by Rick_Findus

  • 13,164 views
  • 6 comments
  • 18 respects

Temperature sensor

Project tutorial by Grant

  • 22,117 views
  • 6 comments
  • 37 respects
Add projectSign up / Login