DIY ELECTRONICSTR

← All projects

DHT11 Temperature and Humidity Meter

Beginner20 min

A starter project that measures the room's temperature and humidity with a DHT11 sensor and writes the values to the Arduino IDE's Serial Monitor once a second. Before uploading the code, install the DHTlib library in the Arduino IDE.

Get it on Google Play

What you need

Wiring steps

  1. 1

    Power the sensor

    Power the sensor

    Plug a red jumper wire into the 5V pin on the Arduino's POWER header. Connect its other end to the top pin of the DHT11 module, marked + (VCC).

    • Arduino 5V → DHT11 + (red wire)
  2. 2

    Connect the data line

    Connect the data line

    Plug a blue jumper wire into the Arduino's digital pin 2. Connect its other end to the middle data (DATA) pin of the DHT11 module. The code reads the sensor on this pin.

    • Arduino pin 2 → DHT11 DATA (blue wire)
  3. 3

    Ground (GND) connection

    Ground (GND) connection

    Plug a black jumper wire into the GND pin on the Arduino's digital header, next to pin 13. Connect its other end to the bottom pin of the DHT11 module, marked −. That completes all three of the sensor's connections.

    • Arduino GND → DHT11 − (black wire)

Arduino sketch

Download the sketch (.ino)

#include <dht.h>

dht DHT;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the
  // DHT11 on pin 2
  int chk = DHT.read11(2);

  // write the temperature
  // to the Serial Monitor
  Serial.print("Temp: ");
  Serial.print(DHT.temperature);
  // '\t' puts a tab
  // between the values
  Serial.print(" °C\t");

  // write the humidity
  // to the Serial Monitor
  Serial.print("Humidity: ");
  Serial.print(DHT.humidity);
  // println ends the line
  // and moves to the next one
  Serial.println(" %");

  delay(1000);
}

What the Serial Monitor shows

SERIAL MONITOR · 9600 BAUD
Temp: 24.00 °C    Humidity: 45.00 %
Temp: 24.00 °C    Humidity: 45.00 %

Similar projects

In the app, tick off every wire, match the parts to your inventory and pick up where you left off.

Get it on Google Play