Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Based Weather Station with DHT11 Sensor and HC-SR05 Ultrasonic Sensor

Image of Arduino-Based Weather Station with DHT11 Sensor and HC-SR05 Ultrasonic Sensor

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with a DHT11 humidity and temperature sensor, an HC-SR05 ultrasonic sensor, and a 16x2 I2C LCD display. The Arduino UNO reads data from the sensors and displays the information on the LCD. The DHT11 sensor measures humidity and temperature, while the HC-SR05 sensor measures distance. The LCD displays the sensor readings.

Component List

DHT11 Humidity and Temperature Sensor

  • Description: Measures humidity and temperature.
  • Pins: VDD, DATA, NULL, GND

Resistor

  • Description: Provides resistance in the circuit.
  • Properties:
    • Resistance: 0 Ohms
  • Pins: pin1, pin2

HC-SR05 Ultrasonic Sensor

  • Description: Measures distance using ultrasonic waves.
  • Pins: VCC, TRIG, GND, ECHO, OUT

Arduino UNO

  • Description: Microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0

16x2 I2C LCD

  • Description: Displays information in a 16x2 character format using I2C communication.
  • Pins: GND, VCC, SDA, SCL

Wiring Details

DHT11 Humidity and Temperature Sensor

  • VDD: Connected to Arduino UNO 5V
  • DATA: Connected to Resistor pin2
  • GND: Connected to Arduino UNO GND

Resistor

  • pin1: Connected to HC-SR05 VCC
  • pin2: Connected to DHT11 DATA and Arduino UNO D10

HC-SR05 Ultrasonic Sensor

  • VCC: Connected to Resistor pin1
  • TRIG: Connected to Arduino UNO D8
  • ECHO: Connected to Arduino UNO D9
  • GND: Connected to Arduino UNO GND

Arduino UNO

  • 5V: Connected to DHT11 VDD, HC-SR05 VCC, and 16x2 I2C LCD VCC
  • GND: Connected to DHT11 GND, HC-SR05 GND, and 16x2 I2C LCD GND
  • D8: Connected to HC-SR05 TRIG
  • D9: Connected to HC-SR05 ECHO
  • D10: Connected to Resistor pin2
  • A4: Connected to 16x2 I2C LCD SDA
  • A5: Connected to 16x2 I2C LCD SCL

16x2 I2C LCD

  • GND: Connected to Arduino UNO GND
  • VCC: Connected to Arduino UNO 5V
  • SDA: Connected to Arduino UNO A4
  • SCL: Connected to Arduino UNO A5

Code Documentation

#include <DHT.h>
#include <LiquidCrystal_I2C.h>

const int PINDHT = 10;
const int DHTTYPE = DHT11;
DHT dht(PINDHT, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int trigPin = 8;
const int echoPin = 9;
long thoigian;
float khoangcach;

void setup() 
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  dht.begin();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() 
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  thoigian = pulseIn(echoPin, HIGH);
  khoangcach = thoigian * 0.0347 / 2.0;

  float doam = dht.readHumidity();
  float nhietdo = dht.readTemperature();
  if (isnan(doam) || isnan(nhietdo)) {
    lcd.setCursor(0, 0);
    lcd.print("Loi cam bien DHT");
  } else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("DA:");
    lcd.setCursor(3, 0);
    lcd.print((int)doam);
    lcd.setCursor(8, 0);
    lcd.print("ND:");
    lcd.setCursor(11, 0);
    lcd.print(nhietdo);
    lcd.setCursor(0, 1);
    lcd.print("KC:");
    lcd.setCursor(4, 1);
    lcd.print(khoangcach, 4);
  }
  Serial.print(" ");
  Serial.print(khoangcach, 4);
  Serial.println();
  delay(300);
}

This code initializes the DHT11 sensor, the HC-SR05 sensor, and the 16x2 I2C LCD. In the setup function, the serial communication, LCD, and sensors are initialized. The loop function continuously reads data from the sensors and displays the humidity, temperature, and distance on the LCD. The distance is also printed to the serial monitor.