Arduino Mega - DHT11
This guide shows how to use the DHT11 temperature and humidity sensor with the Arduino Mega. We will cover the details:
- How to connect the DHT11 sensor and DHT11 module to the Arduino Mega.
- How to write code for the Arduino Mega to read temperature and humidity from the DHT11 sensor and module.

Hardware Preparation
| 1 | × | Arduino Mega | |
| 1 | × | USB 2.0 cable type A/B (for USB-A PC) | |
| 1 | × | USB 2.0 cable type C/B (for USB-C PC) | |
| 1 | × | DHT11 Temperature Humidity Sensor Module | |
| 1 | × | 10 kΩ Resistor | |
| 1 | × | Breadboard | |
| 1 | × | Jumper Wires |
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of DHT11 Temperature and Humidity Sensor
| DHT11 | |
|---|---|
| Operating Voltage | 3 to 5V |
| Temperature Range | 0°C to 50°C |
| Temperature Accuracy | ± 2°C |
| Humidity Range | 20% to 80% |
| Humidity Accuracy | 5% |
| Reading Rate | 1Hz (once every second) |
Pinout
DHT11 has two kinds: a sensor and a module.

The DHT11 sensor has 4 pins.
- GND pin: connect to ground (0V)
- VCC pin: connect to power (5V or 3.3V)
- DATA pin: used to send and receive data between the sensor and the Arduino Mega
- NC pin: not connected, can be ignored
The DHT11 module has three pins.
- Ground pin: connect to ground (0 volts).
- Power pin: connect to the power supply (5 volts or 3.3 volts).
- Data pin: used to send and receive data between the sensor and the Arduino Mega.
Some makers sell the DHT11 sensor as a small module with three pins: GND, VCC, and DATA (or sometimes -, +, and OUT).
Wiring Diagram
To connect the DHT11 sensor to the Arduino Mega, use a resistor of about 5k to 10k ohms. This resistor keeps the data line high, so the sensor and the Arduino can talk properly.
Arduino Mega - DHT11 Sensor Wiring

This image is created using Fritzing. Click to enlarge image
Arduino Mega - DHT11 Module Wiring
Most DHT11 sensor modules already have a resistor built in, so you don’t need to add one. This makes wiring or soldering easier.

This image is created using Fritzing. Click to enlarge image
How To Program For DHT11 Temperature Sensor
Coding for both the sensor and the module is the same.
- Add the library.
- Choose the Arduino Mega pin that connects to the DHT sensor.
- Make a DHT11 sensor.
- Turn on the sensor:
- Check the humidity level
- Read the temperature in Celsius.
- Check the temperature in Fahrenheit.
Arduino Mega Code - DHT11
Detailed Instructions
Do these steps one by one.
- Connect the parts following the diagram.
- Connect the Arduino Mega to your computer with a USB cable.
- Open the Arduino IDE on your computer.
- Choose the Arduino Mega board and the correct COM port.
- Click the Libraries icon on the left side of the IDE.
- In the search box, type DHT and find the Adafruit DHT library.
- Click Install to add the library.

- You need to install more software packages.
- Click the Install All button to install all the needed libraries.

- Copy the code for your sensor and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to upload the code to the Arduino Mega.
- Change the temperature near the sensor to be warmer or cooler.
- See the results in the Serial Monitor.