Digital Thermometer and Hygrometer with LCD

Digital Thermometer and Hygrometer with LCD


                                                                    DHT11SENSOR

Components Needed:

  • Arduino Uno (or any compatible board)
  • LCD Display (16x2) - using <Adafruit_LiquidCrystal.h> library
  • DHT11 Temperature and Humidity Sensor
  • 10kΩ potentiometer (for adjusting LCD contrast)
  • Breadboard and jumper wires

Wiring Diagram:

  1. LCD Display:

    • Connect VSS to GND and VDD to 5V
    • Connect RS to Arduino pin 12
    • Connect RW to GND
    • Connect E (Enable) to Arduino pin 11
    • Connect D4, D5, D6, D7 to Arduino pins 5, 4, 3, 2, respectively
    • Connect the potentiometer:
      • One side to GND
      • Other side to 5V
      • Middle pin to the VO (contrast) pin of the LCD
  2. DHT11 Sensor:

    • Connect VCC to 5V
    • Connect GND to GND
    • Connect the Data pin to Arduino digital pin 7

Explanation:

  1. DHT11 Sensor: The DHT11 sensor measures both temperature and humidity, and we use the DHT library to access these values.
  2. The dht.readTemperature() and dht.readHumidity() functions are used to get temperature and humidity values, respectively.
  3. These values are then displayed on the 16x2 LCD.
  4. The code includes error handling to check if the sensor read fails (isnan(humidity) || isnan(temperature)).

Code

#include <Adafruit_LiquidCrystal.h>
#include <DHT.h>

#define DHTPIN 7          // Pin connected to DHT11 data pin
#define DHTTYPE DHT11     // DHT11 sensor type

Adafruit_LiquidCrystal lcd(0);
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  lcd.begin(16, 2);        // Set up the LCD's number of columns and rows
  lcd.print("Temp & Humidity");
  dht.begin();             // Initialize DHT sensor
  delay(2000);             // Wait for the sensor to get ready
}

void loop() {
  float humidity = dht.readHumidity();           // Read humidity
  float temperature = dht.readTemperature();     // Read temperature in Celsius

  // Check if any reads failed
  if (isnan(humidity) || isnan(temperature)) {
    lcd.setCursor(0, 1);
    lcd.print("Sensor Error   ");
  } else {
    // Display temperature on LCD
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(temperature);
    lcd.print(" C   ");  // Add padding to clear previous readings

    lcd.setCursor(0, 2);
    lcd.print("Humidity: ");
    lcd.print(humidity);
    lcd.print(" %   ");  // Add padding to clear previous readings
  }

  delay(2000); // Update every 2 seconds
}

Summary

  1. Gather all the required components.
  2. Set up the wiring according to the wiring diagram.
  3. Install the required libraries in the Arduino IDE.
  4. Upload the code to the Arduino.
  5. Monitor the LCD to see the temperature and humidity readings.

Comments

Popular posts from this blog

esp8266

1.Using an LDR (Light Dependent Resistor) with Arduino to Measure Light Intensity