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;

DHT dht(DHTPIN, DHTTYPE);

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

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

  // 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(humi);
    Serial.print("%");

    Serial.print("  |  "); 

    Serial.print("Temperature: ");
    Serial.print(tempC);
    Serial.print("C ~ ");
    Serial.print(tempF);
    Serial.println("F");


    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

https://www.youtube.com/watch?v=ZI5UNvz1icw&ab_channel=Codeconia

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

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

Share with your friends:

Comments are closed.

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 […]

September 6, 2021

Ultrasonic Sensor with Arduino Tutorial

What is an Ultrasonic Sensor An ultrasonic sensor is a sensor that can measure the distance to an object. It […]

September 5, 2021

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now