Temperature and Humidity Monitor

Monitor the ambient temperature and humidity in a room using a DHT11 sensor.   Component List:
  • 1 x Arduino Uno R3
  • Jumper Wires
  • 1 x LCD1602 with I2C module
  • 1 x Breadboard
  • 1 x DHT11
Wiring Guide:
  1. Connect the I2C module to the Arduino board:
    • Connect the SDA pin on the I2C module to the A4 pin on the Arduino.
    • Connect the SCL pin on the I2C module to the A5 pin on the Arduino.
    • Connect VCC on the I2C module to the 5V pin on the Arduino (or breadboard).
    • Connect GND on the I2C module to the GND pin on the Arduino (or breadboard).
  2. Connect DHT11 to the Arduino Board:
    • Connect the VCC pin of the DHT11 to 5V on the Arduino (or breadboard).
    • Connect the data pin of the DHT11 to a digital pin 2 on the Arduino.
    • Connect the GND pin of the DHT11 to GND on the Arduino (or breadboard).
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2         // DHT11 data pin connected to D2
#define DHTTYPE DHT11    // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 columns and 2 rows
void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  dht.begin();  // Initialize the DHT sensor
  delay(2000);  // Allow time for sensor to stabilize
}
void loop() {
  float temperature = dht.readTemperature();  // Reading temperature from DHT sensor
  float humidity = dht.readHumidity();        // Reading humidity from DHT sensor
  lcd.clear();  // Clear the LCD display
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperature, 1);  // Display temperature with one decimal place
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(humidity, 1);     // Display humidity with one decimal place
  lcd.print(" %");
  delay(1000);  // polling (1 second)
}
  Quick Troubleshooting: One line of blocks show on the screen This means the wiring is wrong or most likely the LCD was not initialized correctly in the code.  
Two lines of blocks show on the screen Behind the LCD is the i2c module, and a blue potentiometer, slowly turn it one side to another until your characters start to appear
[bitware_arabic_portfolio_content]

Project Details

Level: Beginner (1/5)
Category: Monitoring System
Platform: Arduino
Creator: BitWare Store