How to use Temperature and humidity sensor DHT11 with Arduino tutorial

Hello Everyone,
In this tutorial, we are going to make a small project with Arduino and Temperature and humidity sensor DHT11.
I actually really like to work with Arduino and different sensors. Today I am making a small application when the temperature reaches more than 30-degree celsius an LED will turn on. if the temperate is less than 30 degree celsius the LED will turn off.

You can make home automation tools based on temperature by using this sensor and circuit. if you want to turn on fan or A/C with this. that’s actually possible ..
You just need to use a relay module to make it happen.

Here I am going to create my temperature sensor

Temperature sensor circuit diagram

After making the circuit, you have to upload this code to your Arduino board.

Arduino temperature sensor read code

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
int led = 13;


void setup() {
  pinMode(led, OUTPUT);
  dht.begin(); // initialize the sensor

void loop() {
  // wait a few seconds between measurements.

  // read humidity
  float humi  = dht.readHumidity();
  // read temperature as Celsius
  float tempC = dht.readTemperature();
  // read temperature as Fahrenheit
  float tempF = dht.readTemperature(true);

  // check if any reads failed
  if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");

    Serial.print("  |  "); 

    Serial.print("Temperature: ");
    Serial.print("C ~ ");

    if(tempC > 30.00) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); }


Hope this works well for you .. please let me know if you having any doubts related to this

Share with your friends:

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

HTML Form to Email Using JavaScript and SMTP server 🚀

Hello Everyone, 🙋‍♂️ In this tutorial, we are going to look at how to send emails from HTML Form to […]

22 September, 2021

How to make pretty URL in PHP using .htaccess

Hello Everyone, Here in this tutorial, you will learn How to make a pretty URL in PHP using .htaccess. and […]

18 September, 2021

Submit Form Without Refreshing Page PHP and Javascript

Hello Everyone, In this tutorial, we are going to learn, How to submit a form without reloading. yeah, that’s so […]

HTML from to Email using SMTP in PHP with Source code

Hello Everyone, In this tutorial, I am going to teach you how to send an email from an HTML form […]

16 September, 2021


Subscribe to our weekly Newsletter and stay tuned.

Free PHP Invoicing Software

Gmax CRM Lite is an Invoicing and project management tool for small businesses, features including client management , invoicing , quotation and project management

Download for free