Build a Temperature and Humidity Weather Station using DHT11 Sensor
How to Make a Weather Station with DHT11 Temperature & Humidity Sensor and Arduino Uno


Let's get started with this innovative Arduino tutorial where you will learn about the DHT11 Temperature and Humidity Sensor Module and how to use it with our Arduino Board to create our own weather station project at home.

Components Required:

  1. Arduino Uno
  2. DHT11 Temp & Humidity sensor
  3. 16x2 LCD 
  4. Connecting wires
  5. Breadboard
  6. Power Supply
  7. 10k ohm Potentiometer
  8. 5k ohm Resistor
  9. 560 ohm Resistor

What is a DHT11 Sensor?

The DHT11 module is a temperature and humidity sensing module that uses Digital Signal Acquisition to translate temperature and humidity to a digital reading that a microcontroller can easily read. The DHT11 has a temperature range of 0°C to 50°C, which is ideal for home or hobby use.

The DHT11 Humidity and Temperature Sensor is made up of three main parts. A resistive type humidity sensor, an NTC thermistor (to calculate temperature), and an 8-bit microcontroller that transforms the analog signals from both sensors into a single digital signal.

What is DHT11 Sensor?

VCC, Data Out, NC (Not Connected ), and GND are the four pins on the DHT11 Sensor. 

The voltage range for the VCC pin is 3.5V to 5.5V. A 5V power supply will suffice. Serial digital data is output from the Data Out pin.

The DHT11 Sensor can detect humidity levels ranging from 20% to 90% relative humidity (RH) and temperatures ranging from 0 to 50°C. The sensor's sampling time is one second.

The data from the DHT11 sensor is 40 bits in length and is formatted as follows:

8-bit data for integral RH value, 8-bit data for decimal RH value, 8-bit data for integral Temperature value, 8-bit data for decimal Temperature value,  and 8-bit data for checksum.

Consider the data received from the DHT11 Sensor is 

00100101 00000000 00011001 00000000 00111110.

This data can be separated based on the above mentioned structure as follows:

00100101

0000000

00011001

00000000

00111110

High Humidity

Low Humidity

High Temperature

Low Temperature

Checksum (Parity)


In order to check whether the received data is correct or not, we must perform a small calculation. Check if the sum of the integral and decimal values of RH and Temperature equals the checksum value, i.e. the last 8-bit data.

00100101 + 00000000 + 00011001 + 00000000 = 00111110

This value is the same as the checksum, indicating that the data obtained is right. Simply convert the binary data to decimal data to obtain the RH and Temperature values.

  • RH = Decimal of 00100101 = 37%
  • Temperature = Decimal of 00011001 = 25°C

Initially Arduino sends a high to low start signal to DHT11 with 18µs delay to ensure DHT’s detection. The Arduino then pulls up the data line and waits 20-40µs for DHT to respond. When DHT detects a start signal, it sends a low voltage level response signal to the Arduino with an 80µs delay. The DHT controller then pulls up the data line and holds it for 80µs for DHT’s arrangement of sending data.

When the data bus voltage is low, the DHT11 is sending a response signal. After that, DHT performs another data line pull-up for 80µs to prepare data transmission.

Data format that is sent by DHT to the Arduino for every bit starts with 50µs low voltage level and length of high voltage level signal decides whether data bit is 0 or 1.

How to Interface 16x2 LCD with Arduino Uno ?

LCD modules are a critical component in many Arduino-based embedded systems. As a result, understanding how to attach an LCD module to an Arduino is crucial when designing embedded systems. Here you will learn how to connect an Arduino to a 16x2 LCD display. 

The JHD162A is a 16x2 LCD module based on Hitachi's HD44780 driver. The JHD162A has 16 pins and can be used in 4-bit or 8-bit mode (using only four data lines) or (using all 8 data lines) respectively. In this case, the LCD module is set to 4-bit mode.

Before going into the details of the project, let’s have a look at the JHD162A LCD module.The schematic of a JHD162A LCD pin diagram is given below.

How to Interface 16x2 LCD with Arduino Uno ?, 16x2 LCD, 16x2 LCD pinout

Pinout:

  • Pin1(Vss): Ground pin of the LCD module.
  • Pin2(Vcc): Power to LCD module (+5V supply is given to this pin)
  • Pin3(VEE): Contrast adjustment pin. This is done by connecting the ends of a 10K potentiometer to +5V and ground and then connecting the slider pin to the VEE pin. The voltage at the VEE pin defines the contrast. The normal setting is between 0.4 and 0.9V.
  • Pin4(RS): Register select pin.The JHD162A has two registers namely command register and data register. Logic HIGH at RS pin selects data register and logic LOW at RS pin selects command register. If we make the RS pin HIGH and feed an input to the data lines (DB0 to DB7), this input will be treated as data to display on the LCD screen. If we make the RS pin LOW and feed an input to the data lines, then this will be treated as a command ( a command to be written to LCD controller – like positioning cursor or clear screen or scroll).
  • Pin5(R/W): Read/Write modes. This pin is used for selecting between read and write modes. Logic HIGH at this pin activates read mode and logic LOW at this pin activates write mode.
  • Pin6(E): This pin is meant for enabling the LCD module. A HIGH to LOW signal at this pin will enable the module.
  • Pin7(DB0) to Pin14(DB7):  These are data pins. The commands and data are fed to the LCD module though these pins.
  • Pin15(Backlight +): Anode of the back light LED. When operated on 5V, a 560 ohm resistor should be connected in series to this pin. In arduino based projects the back light LED can be powered from the 3.3V source on the arduino board.
  • Pin16(Backlight -): Cathode of the back light LED.

Circuit Diagram

Circuit Diagram of Weather Station with DHT11 and Arduino Uno


Connect the LCD module's RS pin  to the Arduino's digital pin 12.

LCD's R/W pin to GND. 

LCD module enable pin to the Arduino's digital pin 11. The LCD module and the Arduino are connected in 4-bit mode in this project. This means that only four of the LCD's digital input lines (DB4 to DB7) are used.

This method is very simple and needs fewer connections, and allows you to almost fully leverage the LCD module's capabilities. The digital lines DB4, DB5, DB6, and DB7 are connected to the Arduino's digital pins 5, 4, 3, and 2. The 10K potentiometer is used for controlling the contrast of the light. The current through the back light LED is limited by the 560 ohm resistor R1.

About 16x2 LCD Program

A built-in library in Arduino called LiquidCrystal.h> to enable communication between the Arduino and the LCD module is used here. This library is written for LCD modules that use the Hitachi HD44780 chipset (or a compatible chipset). This library can accommodate LCD wiring in both 4 bit and 8 bit modes.


By simply calling the lcd.print() method, a data string can be printed on the LCD module.

To begin, use lcd.setCursor(row,column) to place the cursor in the desired location.

LiquidCrystal lcd() – is  a constructor used to declare a variable of its kind. Here ‘lcd’ is the variable declared using the constructor and is used to call methods defined inside the library LiquidCrystal.h

lcd.begin() – is used to initialize the lcd screen and transfer the screen's dimensions (columns and rows) as parameters to the process.

The method lcd.scrollDisplayRight() scrolls the display to right and the method lcd.scrollDisplayLeft() scrolls the display to left.


Setup Arduino IDE

Install DHT Sensor library
Install LiquidCrystal library

After installing suitable library open new sketch and upload the code given below:

Arduino Code


#include "DHT.h"
#include <LiquidCrystal.h>
#define DPIN 6        // Digital pin connected to the DHT sensor
#define DTYPE DHT11   // DHT 11
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
DHT dht(DPIN, DTYPE);
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  dht.begin();
}
void loop() {
  delay(500);
  
  lcd.setCursor(0, 0);
  lcd.print("Humidity: ");
  lcd.print(dht.readHumidity());
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("Temp: ");
  lcd.print(dht.readTemperature());
  lcd.print((char)223);
  lcd.print("C");
}

How is the program working ?

We imported the DHT and LiquidCrystal libraries in the first two lines of this code. Then we created a variable DPIN to hold the PIN to which the DHT11 data pin is attached. Next, we created a new variable DTYPE, which contains the name of the sensor's type (DHT11 or DHT22)

Similarly, rs, en, d4, d5, d6, and d7 are the pins of the LCD whose values are assigned to the number of the pins they are attached to respectively. To set up our LCD and sensor, we now use two functions called LCD and DHT.

The setup() function is then used to start our LCD display and DHT11 sensor. Since the setup() function only runs once after the project is powered on, the syntax in it starts the LCD and sensor at the beginning.

After that, we'll look at the loop() feature. Since we need a time interval to display the results, we added a delay of 0.5 seconds or 5000 milliseconds. Following that, we declared two float variables, ‘h' and ‘t.' The letters ‘h' and ‘t' represent the percentage value of humidity and the centigrade value of temperature, respectively.

The loop() function's if statement tests if we're getting both humidity and temperature; otherwise, the LCD will show "Failed to read from DHT sensor!" The following lines of code simply provide the syntax for printing our result on the LCD.

Diy projects

Leave a comment

All comments are moderated before being published