Temperature and Humidity Sensor (DHT11)
Anand RamaswamiShare
Welcome Back, Maker!
So far you have learned how to read buttons, control LEDs, spin motors, move a servo, and react to light using sensors.
But many smart systems do something even more useful:
they measure the environment.
They do not just respond to a button press.
They look at the world around them and decide what to do.
For example:
- a weather station checks temperature and humidity
- a fan turns ON automatically when it gets too hot
- a greenhouse watches moisture and air conditions
- a room monitor tells you if the air feels comfortable
To build systems like that, we need a sensor that can measure both temperature and humidity.
That is where the DHT11 sensor comes in.
What Is the DHT11 Sensor?
The DHT11 is a simple sensor that measures two things:
- Temperature
- Humidity
Temperature tells us how hot or cold the air is.
Humidity tells us how much water vapor is present in the air.
So instead of only checking one condition, the DHT11 gives us two useful environmental readings at the same time.
That is why it is commonly used in beginner weather stations and smart monitoring projects.
What Is Temperature?
Temperature tells us how hot or cold something is.
Examples:
- a cold room might be 20°C
- a warm room might be 30°C
- a very hot place might be 40°C
Temperature is one of the most important measurements in electronics because many systems depend on heat conditions.
For example:
- fans turn on when temperature rises
- fire warning systems watch for high temperature
- weather stations show room temperature
- smart homes react to hot and cold conditions
What Is Humidity?
Humidity tells us how much moisture is in the air.
If the humidity is high, the air feels wet or sticky.
If the humidity is low, the air feels dry.
Examples:
- low humidity → dry air
- medium humidity → comfortable air
- high humidity → damp or sticky air
Humidity is useful in projects like:
- weather stations
- greenhouse monitors
- room comfort systems
- storage condition monitoring
So with one sensor, the DHT11 can tell us both how hot the air is and how moist it is.
How Does the DHT11 Work?
Inside the DHT11, there are parts that measure:
- temperature
- humidity
The sensor reads those values internally and then sends the data to Arduino as a digital signal.
That means we do not use analogRead() here like we did with the potentiometer or LDR.
Instead, we use a special library that understands the signal sent by the DHT11.
So this sensor is different from many earlier sensors:
- Potentiometer → analog value
- LDR → analog value
- DHT11 → digital temperature and humidity data
Why Use DHT11?
The DHT11 is useful because it gives two important environmental readings in one sensor.
It is great for beginner projects because:
- it is easy to use
- it is small
- it is low-cost
- it works well for simple room monitoring projects
It may not be the most advanced sensor, but it is perfect for learning how smart sensing systems work.
The Library We Need
To read data from the DHT11, we use the DHT library.
This library helps Arduino understand the special digital signal sent by the sensor.
The commands we use are:
|
#include <DHT.h> |
This includes the DHT library.
|
#define DHTPIN A0 #define DHTTYPE DHT11 |
This tells Arduino which pin the sensor is connected to and which type of DHT sensor we are using.
| DHT dht(DHTPIN, DHTTYPE); |
This creates a DHT sensor object.
|
dht.begin(); |
This starts the sensor.
float temp = dht.readTemperature();
float hum = dht.readHumidity();
These commands read the temperature and humidity values from the sensor.
Now that we know what the DHT11 does and how Arduino reads it, let us begin with the simplest project: showing the readings like a mini weather monitor.
Project 1: Weather Monitor
In this project, Arduino reads the temperature and humidity from the DHT11 and shows them on the Serial Monitor.
This is the best first project because it helps us see the raw sensor values clearly.
Code:
|
#include <DHT.h> #define DHTPIN A0 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C"); Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %"); Serial.println("-------------------"); delay(2000); } |
Explanation:
#include <DHT.h> loads the DHT library.
#define DHTPIN A0 tells Arduino that the DHT11 data pin is connected to A0.
#define DHTTYPE DHT11 tells the library that this is a DHT11 Sensor.
DHT dht(DHTPIN, DHTTYPE); creates the sensor object.
Serial.begin(9600); starts the Serial Monitor communication.
dht.begin(); starts the DHT11 sensor.
dht.readTemperature(); reads the temperature in degree Celsius.
dht.readHumidity(); reads the humidity percentage.
Serial.print() and Serial.println() show the values on the Serial Monitor.
delay(2000); waits 2 seconds before taking the next reading. The DHT11 should not be read too fast, so this delay is important.
Upload the code, open the Serial Monitor, and you will see a live stream of room temperature and humidity.
This project works like a simple indoor weather monitor.
Reading values on the Serial Monitor is a great start. But smart systems usually do more than just display information.
Output:
They use that information to control something automatically.
A perfect next step is to use the temperature reading to control a fan.
Project 2: Auto Fan Control System with Temperature on OLED
In this project, the DHT11 checks the room temperature.
If the temperature becomes too high, your small fan motor turns ON automatically.
If the temperature drops again, the fan turns OFF.
At the same time, the OLED display shows the current temperature and fan status.
This makes the project feel like a real smart cooling system:
sensor reads condition → Arduino makes decision → fan reacts automatically → OLED shows live status
Code:
|
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C #define DHTPIN A0 #define DHTTYPE DHT11 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); DHT dht(DHTPIN, DHTTYPE); void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); display.clearDisplay(); display.display(); Serial.begin(9600); dht.begin(); } void loop() { float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); display.clearDisplay(); display.setTextColor(SSD1306_WHITE); display.setTextSize(1); display.setCursor(0, 0); display.println("Auto Fan System"); display.setCursor(0, 16); display.print("Temp: "); display.print(temperature); display.println(" C"); display.setCursor(0, 28); display.print("Humidity: "); display.print(humidity); display.println(" %"); display.setCursor(0, 46); if (temperature > 30) { digitalWrite(9, HIGH); digitalWrite(10, LOW); display.println("Fan: ON"); Serial.println("Fan ON"); } else { digitalWrite(9, LOW); digitalWrite(10, LOW); display.println("Fan: OFF"); Serial.println("Fan OFF"); } display.display(); Serial.print("Temperature: "); Serial.println(temperature); delay(2000); } |
Explantion:
#include <Wire.h> loads the I2C communication library for the OLED.
#include <Adafruit_GFX.h> and #include <Adafruit_SSD1306.h> load the OLED display libraries.
#include <DHT.h> loads the DHT11 sensor library.
pinMode(9, OUTPUT); and pinMode(10, OUTPUT); set the motor control pins as outputs.
display.begin(...) starts the OLED display.
dht.begin(); starts the DHT11 sensor.
dht.readTemperature(); reads the current room temperature.
dht.readHumidity(); reads the humidity.
The OLED shows:
- project title
- temperature
- humidity
- fan status
Then the program checks the temperature.
If the temperature is greater than 30°C:
- D9 goes HIGH
- D10 goes LOW
- the small fan motor turns ON
- the OLED shows Fan: ON
If the temperature is 30°C or below:
- both motor pins go LOW
- the fan stops
- the OLED shows Fan: OFF
display.display(); sends all the text to the OLED screen.
delay(2000); waits 2 seconds before taking the next reading.
This project is a great example of a smart cooling system because it both acts and shows information at the same time.
Output:

An automatic fan is a very useful output project. But sometimes we do not want to turn on a motor or sound a buzzer.
Sometimes we just want the system to clearly show us a warning on a screen.
That makes the OLED display a perfect next step for a smart temperature alert system.
Project 3: Temperature Alert on OLED
In this project, the DHT11 reads the temperature and shows a warning message on the OLED display when the room becomes too hot.
If the temperature is normal, the OLED shows that the room is safe.
If the temperature rises above a set limit, the OLED shows a high temperature alert.
This is a simple example of a smart monitoring system with a live display.
Code:
|
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C #define DHTPIN A0 #define DHTTYPE DHT11 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); DHT dht(DHTPIN, DHTTYPE); void setup() { display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); display.clearDisplay(); display.display(); dht.begin(); } void loop() { float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); display.clearDisplay(); display.setTextColor(SSD1306_WHITE); display.setTextSize(1); display.setCursor(0, 0); display.println("Temperature Alert"); display.setCursor(0, 16); display.print("Temp: "); display.print(temperature); display.println(" C"); display.setCursor(0, 28); display.print("Humidity: "); display.print(humidity); display.println(" %"); display.setCursor(0, 46); if (temperature > 32) { display.setTextSize(2); display.println("HOT!"); } else { display.setTextSize(1); display.println("Room is Normal"); } display.display(); delay(2000); } |
Explanation:
#include <Wire.h> loads the I2C communication library for the OLED.
#include <Adafruit_GFX.h> and #include <Adafruit_SSD1306.h> load the OLED display libraries.
#include <DHT.h> loads the DHT sensor library.
Adafruit_SSD1306 display(...) creates the OLED display object.
DHT dht(DHTPIN, DHTTYPE); creates the DHT11 sensor object.
display.begin(...) starts the OLED display.
dht.begin(); starts the DHT11 sensor.
dht.readTemperature(); reads the room temperature.
dht.readHumidity(); reads the humidity.
display.clearDisplay(); clears the screen before drawing new data.
The OLED first shows:
- the project title
- current temperature
- current humidity
Then the program checks the temperature.
If the temperature is greater than 32°C, the OLED shows:
HOT!
If the temperature is below that limit, the OLED shows:
Room is Normal
display.display(); sends everything to the screen.
delay(2000); waits 2 seconds before the next reading.
This makes the OLED act like a small live temperature warning display.
Output:

Real-Life Examples of DHT11-Type Systems
Temperature and humidity sensing is used everywhere around us.
A digital weather station measures room conditions and shows them on a display.
A greenhouse control system watches heat and humidity to protect plants.
A smart fan checks room temperature and turns on automatically.
A storage room monitor checks whether the environment is too humid.
A baby room monitor may track room comfort so the space does not get too hot.
The common idea is simple:
the system reads the environment and then either displays, reacts, or alerts.
What You Learned in This Blog
You started this blog with a new kind of environmental sensor.
Now look at what you understand.
You know what the DHT11 sensor measures:
- temperature
- humidity
You know the difference between them.
You know that the DHT11 sends digital data, not analog values.
You know that we use the DHT library to read the sensor.
You built projects that:
- display temperature and humidity like a weather monitor
- automatically control a fan based on heat
- give a buzzer warning when temperature gets too high
This is an important step in embedded systems because now your board is not just reacting to buttons or light.
It is measuring the air around it and making decisions from it.
That is how smart monitoring systems begin.
Keep experimenting, keep building, and keep making.