Components needed

  • DHT11 Sensor
  • Jumper cables
  • A breadboard
  • An Arduino Board
  • A computer with the Arduino IDE installed

Completed Circuit

The Program

#include <DHT.h>
#include <DHT_U.h>

DHT dht(2, DHT11);

float tempInCelcius;
float tempInFarenheit;
float humidity;

void setup() {
  Serial.println("Humidity and Temperature Sensor Program");

void loop() {


  Serial.print("Humidity = ");
  Serial.print(" Tempreture = ");

This is the completed program for the DHT11 Temperature and Humidity Sensor. As you can see we included two libraries, DHT.h and DHT_U.h. We are using the library to read the temperature and humidity out of the sensor.

On line 5, we are declaring the object of library DHT. The declaration takes two parameters. The pin number, where sensor is connected to and type of sensor. In our circuit, we have connected sensor’s output pin to digital pin number 2 on the board and the type of sensor we are using is DHT11.

We have declared 3 variables, tempInCelsius, tempInFarenheit, and humidity of the type float.

In the setup function, we are setting up the serial communication with Serial.begin(9600). After that, we are initializing the library with dht.begin. You can look more about the DHT library at

In the loop function, we are first starting off by delaying for 2 seconds. We are reading the temperature using the dht.readTemperature using the library. This gives the tempreture in Celsius. Later we converted the temperature from Celsius to Fahrenheit using the formula F=C*9/5+32. We are also reading the humidity using the dht.readHumidity function.

Finally we are printing the humidity and temperature using the Serial.print function into the serial monitor.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s