Arduino Tutorial: Temperature and Humidity Alert System with DHT11 Sensor and Buzzer
What Is the DHT11 Sensor?
The DHT11 is an affordable digital sensor module that simultaneously measures temperature and relative humidity. It communicates over a single digital pin, making it ideal for simple Arduino projects. With an operating range of 0–50 °C for temperature and 20–90% RH (relative humidity), it offers a good balance of cost and performance for hobby applications.
How the DHT11 Sensor Works
Internally, the DHT11 uses a resistive-type humidity sensor paired with an NTC thermistor for temperature measurement. A small microcontroller samples both and sends the data as a timed digital signal. Because the sensor uses internal calibration, you get reasonably accurate readings without manual adjustments—just read, parse, and display.
How to Use DHT11 with Arduino
Wiring Diagram
Follow these connections to wire the DHT11 module and buzzer to your Arduino Uno:
- DHT11 VCC → Arduino 5 V
- DHT11 GND → Arduino GND
- DHT11 DATA → Arduino Digital Pin 2
- 10 kΩ pull-up resistor between DATA and 5 V
- Buzzer + → Arduino Digital Pin 8
Buzzer – → Arduino GND

Complete Code
Upload the following sketch to your Arduino. It reads temperature and humidity every two seconds, prints values to Serial Monitor, and sounds the buzzer if thresholds are exceeded.
#include <DHT.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // Sensor model
#define BUZZER_PIN 8 // Buzzer pin
// Set your alert thresholds
const float TEMP_THRESHOLD = 30.0; // °C
const float HUM_THRESHOLD = 70.0; // %
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check for failed readings
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Error: Failed to read from DHT11 sensor");
delay(2000);
return;
}
// Print readings
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Alert logic
if (temperature > TEMP_THRESHOLD || humidity > HUM_THRESHOLD) {
digitalWrite(BUZZER_PIN, HIGH); // Sound the buzzer
} else {
digitalWrite(BUZZER_PIN, LOW); // Silence the buzzer
}
delay(2000); // Wait before next reading
}
Conclusion
You now have a working Arduino alert system that monitors temperature and humidity using the DHT11 sensor and notifies you via a buzzer. Feel free to customize the threshold values, add an LCD or OLED display, or even send readings to the cloud for remote monitoring. This modular setup can be extended to greenhouse controls, weather stations, and home automation projects—unleash your creativity!
Frequently Asked Questions
How to: Arduino Tutorial: Temperature and Humidity Alert System with DHT11 Sensor and Buzzer
Build a temperature and humidity alert system using an Arduino Uno, DHT11 sensor, and buzzer. This tutorial covers how the DHT11 measures environmental con
Required Supplies
- Arduino Board
- Jumper Wires
- Breadboard
- LED
- Resistor
Required Tools
- Arduino IDE
- USB Cable
- Computer
Steps
1Setup Development Environment
2Connect Hardware Components
3Write and Upload Code
4Test and Troubleshoot
Comments (0)
No comments yet. Be the first to comment!
Leave a Comment