Arduino DHT11 Temperature Sensor

Arduino DHT11 Temperature Sensor

Introduction

In this blog post, we will explore Arduino DHT11 Temperature Sensor to create a versatile temperature and humidity monitoring system for your projects. In today’s interconnected world the ability to monitor and control environmental conditions is becoming increasingly important. Whether you are designing a smart home or a greenhouse weather monitoring system having accurate and reliable data on temperature and humidity is crucial.

Components Required

1Arduino Uno Board: The Arduino Uno is a popular microcontroller board that forms the core of our system. It provides the necessary processing power and connectivity options.
2DHT11 Sensor: The DHT11 sensor is a low-cost module capable of accurately measuring temperature and humidity. It offers a simple and reliable solution for our monitoring system.
3Breadboard and Jumper Wires: These components are essential for creating the necessary connections between the Arduino board and the DHT11 sensor.
4USB Cable: A USB cable is required to connect the Arduino board to your computer for programming and power supply.
5Arduino Uno Board: The Arduino Uno is a popular microcontroller board that forms the core of our system. It provides the necessary processing power and connectivity options.

Connections:

Now let’s move on to the connections. Follow these steps to properly wire the components:

1Connect the VCC pin of the DHT11 sensor to the 5V pin on the Arduino Uno board.
2Connect the GND pin of the DHT11 sensor to the GND pin on the Arduino Uno board.
3Connect the data pin (usually labeled as DOUT or DATA) of the DHT11 sensor to any digital pin on the Arduino Uno board (e.g., pin 2).
Arduino DHT11 Temperature Sensor
Arduino DHT11 Temperature Sensor

Code

#include <DHT.h>

#define DHTPIN 2       // Pin connected to the DHT11 sensor

// Uncomment the type of sensor you're using
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  delay(2000);  // Delay between readings

  float temperature = dht.readTemperature();      // Read temperature in Celsius
  float humidity = dht.readHumidity();            // Read humidity percentage

  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print(" °C");

  Serial.print("    Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
}

Got Error ? … Make sure you have the DHT.h library installed in your Arduino IDE software before uploading this code. – If you haven’t installed it already you can do so by selecting “Sketch” -> “Include Library” -> “Manage Libraries” and then searching for “DHT” and installing the library provided by Adafruit ( Download DHT.h library Here ) Once uploaded – then open the Serial monitor & baud rate of “9600” and you will see the temperature and humidity readings printed in the serial monitor every two seconds.

please note that you may need to adjust the pin number DHTPIN in the code if you have connected the data pin of the DHT11 sensor to a different pin on your Arduino uno board.