
Sea Voyage
Robo Explorers 2
Humidity & Temperature Sensor
DHT11 Sensor
The DHT11 is a small and powerful sensor that can measure temperature and humidity in the air!
It works like a mini weather station inside your project! Whether it’s hot, cold, dry, or humid, the DHT11 sensor can tell you!
✅ Measures temperature in °C (Celsius) or °F (Fahrenheit)
✅ Measures humidity (how much water is in the air)
✅ Uses only one pin to send data to Arduino
The Science Behind DHT11!
The DHT11 sensor has two parts inside that help it measure temperature and humidity:
1️⃣ Temperature Sensor: Measuring Heat
Inside the DHT11, there is a tiny thermistor (a type of resistor that changes with temperature).
When the temperature changes, the resistance inside the thermistor changes too!
The sensor measures this resistance and converts it into temperature data!
2️⃣ Humidity Sensor: Measuring Moisture
The DHT11 also has a special layer that absorbs water from the air.
When there is more water in the air (humid conditions), this layer stores more charge.
The sensor measures this change and tells us the humidity level (0% to 100%)!
🔹 Example:
✅ If it’s raining, the humidity is high (80-100%)
✅ If you are in a desert, the humidity is low (10-20%)
Real-Life Uses of the DHT11 Sensor
1. Smart Home Systems – Your air conditioner can adjust automatically based on temperature & humidity!
2. Plant Monitoring – Helps keep plants in the right temperature & moisture conditions!
3. Weather Stations – Used in DIY weather stations to report local conditions!
4. Medical Devices – Some hospitals use it to maintain room conditions for patients!
5. IoT Smart Gadgets – Works with WiFi & Bluetooth to send data to smartphones
How to connect DHT11 Sensor on the Blue Elixer Board
Code Breakdown: DHT11 Sensor with Arduino!
Now, let’s write a program to read temperature & humidity from the DHT11 sensor and display it on the serial monitor!
Code Breakdown (How It Works!)
1️⃣ Including the DHT11 Library
This library helps the Arduino communicate with the DHT11 sensor easily.
2️⃣ Defining the Sensor Pin
The DHT11 sensor is connected to pin 11 on the Arduino.
We use
#define
so we can easily change the pin later if needed.
3️⃣ Creating the DHT Object
This creates a sensor object called
DHT
so we can read data from the sensor.
4️⃣ Setting Up Serial Communication in setup()
This allows the Arduino to send sensor data to your computer’s Serial Monitor!
5️⃣ Reading Temperature & Humidity in loop()
This reads temperature & humidity from the DHT11 sensor.
6️⃣ Displaying Temperature & Humidity on Serial Monitor
This prints temperature & humidity data to the Serial Monitor in a readable format!
7️⃣ Adding a Delay to Avoid Rapid Readings
The DHT11 can only be read every 2 seconds, so we add a delay.
What You’ll See!
1️⃣ Open the Serial Monitor (Ctrl + Shift + M in Arduino IDE).
2️⃣ You’ll see real-time temperature & humidity readings update every 2 seconds!
Fun Activity!
In this activity, you will program your Arduino Nano to use the DHT11 temperature and humidity sensor along with five LEDs to create a temperature warning system.
The system will monitor the current temperature and use the LEDs to visually indicate how hot or cold it is.
If the temperature is low, fewer LEDs will turn on.
If the temperature is high, all LEDs will turn on, acting as a warning.
This is similar to real-life warning systems used in factories, greenhouses, and smart homes to monitor temperature changes.
How It Works
1. Setting Up the Components in setup()
The DHT11 sensor is set up to measure temperature and humidity.
The five LEDs are configured as outputs so they can be controlled by the Arduino.
2. Reading Temperature from the DHT11 Sensor
The DHT11 sensor is read using the
DHT.read()
function.The temperature value is stored in the
temperature
variable.
3. Displaying Temperature in the Serial Monitor
This prints the current temperature to the Serial Monitor.
You can view this in Arduino IDE → Tools → Serial Monitor.
4. Controlling LEDs Based on Temperature
Temperature Range | LEDs Turned On |
---|---|
Below 15°C (Very Cold) | 1 LED |
15°C - 24°C (Cool) | 2 LEDs |
25°C - 29°C (Warm) | 3 LEDs |
30°C - 34°C (Hot) | 4 LEDs |
Above 35°C (Very Hot) | All 5 LEDs |
If the temperature is very cold (<15°C) → Only one LED turns on.
If the temperature is between 15°C and 25°C → Two LEDs turn on.
If the temperature is warm (25°C - 29°C) → Three LEDs turn on.
If the temperature is hot (30°C - 34°C) → Four LEDs turn on.
If the temperature is very hot (above 35°C) → All five LEDs turn on.
What You’ll See
The serial monitor will display temperature readings every 2 seconds.
The LEDs will turn on based on the temperature:
Low temperature → Few LEDs ON.
High temperature → All LEDs ON.