DHT11 Sensor Experiment

DHT11 Temperature and Humidity Sensor Experiment

Introduction

The DHT11 sensor is used to measure temperature and humidity. This experiment demonstrates how to interface the DHT11 with an Arduino to display readings on the Serial Monitor.

Components Needed

Circuit Setup

  1. Connect the VCC pin of the DHT11 to the 5V pin on the Arduino.
  2. Connect the GND pin of the DHT11 to the GND of the Arduino.
  3. Connect the DATA pin of the DHT11 to digital pin 2 on the Arduino.
  4. Place a 10kΩ pull-up resistor between the DATA pin and VCC.

Ensure all connections are secure and the DHT11 is oriented correctly on the breadboard.

Code for DHT11

Upload the following code to your Arduino to read data from the DHT11 sensor:


// Include the necessary library
#include 

// Define the DHT11 sensor type and pin
#define DHTTYPE DHT11
#define DHTPIN 2

// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    Serial.begin(9600);
    Serial.println("DHT11 Temperature and Humidity Sensor Experiment");
    dht.begin();
}

void loop() {
    // Read temperature and humidity values
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();

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

    // Print the results to the Serial Monitor
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");

    delay(2000); // Wait 2 seconds before taking the next reading
}
            

Explanation

The code initializes the DHT11 sensor and reads temperature and humidity data every 2 seconds. The readings are then displayed on the Serial Monitor:

Troubleshooting