Categories: Arduino Projects

DIY Weather Station with DHT11 Sensor

Introduction

Ever wondered how weather stations work and how you can build one yourself? With just a few components and basic programming knowledge, you can create a DIY weather station using a DHT11 sensor to monitor temperature and humidity. This project is perfect for beginners in electronics and IoT enthusiasts who want to track local climate conditions.

What is a DHT11 Sensor?

weather station with DHT11: The DHT11 module

The DHT11 is a low-cost, digital sensor used for measuring temperature and humidity. It provides reliable readings and is widely used in weather monitoring systems, smart homes, and other IoT applications.

Read Also: How to Make Money on TikTok: Your Ultimate Guide

Features of the DHT11 Sensor

  • Measures temperature from 0 to 50°C
  • Humidity range: 20% to 90% RH
  • Operates on 3.3V to 5V power supply
  • Digital output via a single data pin

Components Required

The Arduino Nano board used for the project

To build this DIY weather station, you need the following components:

  • Arduino Uno (or any compatible microcontroller)
  • DHT11 sensor
  • 16×2 LCD display (optional, for real-time display)
  • I2C module (for interfacing the LCD)
  • Resistors and jumper wires
  • Breadboard
  • ESP8266 Wi-Fi module (for IoT functionality, optional)

You May also like: The Thing That Went Wrong with Today’s Youths

How the Weather Station Works

This weather station continuously reads temperature and humidity data from the DHT11 sensor. The data is displayed on an LCD screen and can also be sent to an IoT platform for remote monitoring. We will later add an ESP8266-01 module and with this ESP8266 module included, the data can be uploaded to a cloud dashboard like ThingSpeak.

Read Also: IoT Based Automatic Changeover With Auto Gen Start/Stop

Circuit Diagram

Setting Up the Project

Step 1: Connecting the Components

  1. Connect the VCC pin of the DHT11 sensor to 5V on the Arduino.
  2. Connect the GND pin to the GND of the Arduino.
  3. Connect the Data pin to digital pin 2 of the Arduino.
  4. Connect the LCD display to the Arduino using the I2C module.
  5. If using ESP8266, connect it via TX/RX pins and configure it for data transmission.

Step 2: Installing the Required Libraries

Before coding, install the necessary libraries in the Arduino IDE:

  • DHT Sensor Library
  • Adafruit Unified Sensor Library
  • LiquidCrystal_I2C Library (for LCD interface)

To install these:

  1. Open Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for the required libraries and install them.

Program Code

#include "DHT.h"
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

// LCD Configuration
const int rs = 5, en = 6, d4 = 7, d5 = 8, d6 = 9, d7 = 10;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// DHT22 Sensor Configuration
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// SoftwareSerial for ESP-01 Communication
SoftwareSerial myNewSerial(2, 3); // RX, TX

// Rain Sensor
#define RAIN_SENSOR_PIN A0

float humidity, temperature, rainLevel;

void setup() {
    lcd.begin(16, 2);
    dht.begin();
    Serial.begin(9600);
    myNewSerial.begin(9600);

    lcd.setCursor(3, 0);
    lcd.print("WELCOME");
    lcd.setCursor(3, 1);
    lcd.print("TIMEYIN");
    delay(3000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("IoT WEATHER PRE-");
    lcd.setCursor(0, 1);
    lcd.print("DICTION PROJECT");
    delay(3000);
    lcd.clear();
}

void readSensors() {
    humidity = dht.readHumidity();
    temperature = dht.readTemperature();

    if (isnan(humidity) || isnan(temperature)) {
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
    }

    rainLevel = analogRead(RAIN_SENSOR_PIN) * 5.0 / 1023.0;
}

void displaySensorReadings() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("T:");
    lcd.print(temperature, 1);
    lcd.print("'C");
    lcd.setCursor(9, 0);
    lcd.print("H:");
    lcd.print(humidity, 1);
    lcd.print("%");

    lcd.setCursor(0, 1);
    lcd.print("Rain: ");
    lcd.print(rainLevel, 2);
    lcd.print("mm");
}

void sendToESP() {
    readSensors();
    displaySensorReadings();

    String dataToSend = "humi:" + String(humidity) + ",temp:" + String(temperature) + ",rain:" + String(rainLevel) + "\n";
    myNewSerial.println(dataToSend);

    Serial.println("Data Sent: " + dataToSend);
    delay(2000);
}

void loop() {
    sendToESP();
}

Uploading and Testing the Code

  1. Connect your Arduino to the PC using a USB cable.
  2. Open the Arduino IDE and paste the program code.
  3. Select the correct board and COM port.
  4. Click Upload to flash the code onto the Arduino.
  5. Open the Serial Monitor to check if the readings are displaying correctly.

Enhancing the Weather Station

Adding IoT Functionality

With an ESP8266 Wi-Fi module, you can send data to an IoT platform such as:

  • ThingSpeak (for graphical data visualization)
  • Blynk (for mobile monitoring)
  • Firebase (for cloud storage)

The Arduino code above contains a code snippet where you can connect the ESP-01 module and send the data to Thingspeak. You can reach out to us to get this code for free.

Improving Accuracy

For better accuracy, consider upgrading to a DHT22 sensor, which provides a wider temperature and humidity range.

Battery Power Option

To make your weather station portable, use a Li-ion battery with a voltage regulator.

Applications of DIY Weather Station

  • Home climate monitoring
  • Smart agriculture
  • Environmental research
  • School science projects

Conclusion

Building a DIY weather station with a DHT11 sensor is a fun and educational project. Whether you use it for home automation or IoT applications, this setup provides a simple yet effective way to monitor environmental conditions.

FAQs

1. Can I use a DHT22 sensor instead of DHT11?
Yes! The DHT22 offers higher accuracy and a broader temperature range.

2. Why is my DHT11 sensor showing incorrect readings?
Ensure proper wiring, power supply, and avoid placing the sensor in direct sunlight.

3. How often does the DHT11 update data?
The DHT11 updates temperature and humidity readings every 2 seconds.

4. Can I store the data for later analysis?
Yes, you can log data to an SD card or send it to a cloud database for storage and analysis.

5. How can I make my weather station more advanced?
You can add barometric pressure sensors, wind speed sensors, and rain gauges for a more comprehensive weather station.

smartechlabs

Recent Posts

Unlocking AI Income Strategies: Your Guide to Earning in the Digital Age

Artificial Intelligence (AI) isn't just a buzzword; it's a revolution reshaping how we live and…

5 days ago

An Introduction to Electrical Machine Control Systems

Introduction Electrical machine control systems play a crucial role in modern industrial and commercial applications.…

1 week ago

How AI is Transforming Online Learning and Personalized Education

Read More: AI in Predictive Supply Chain Analytics for Demand Planning Artificial Intelligence (AI) is…

3 weeks ago

Real-World Applications of Electrical Machine Control Systems

Electrical machine control systems are essential across various industries, enabling automation, efficiency, and safety in…

3 weeks ago

The Basics of Programmable Logic Controllers (PLCs)

Programmable Logic Controllers (PLCs) are the backbone of modern industrial automation. Read More: How to…

3 weeks ago

How to Optimize Machine Performance with Control Systems

Optimizing machine performance is essential for improving efficiency, reducing operational costs, and extending equipment lifespan.…

3 weeks ago