sensor-experiments

Introduction

The DHT11 sensor is a low-cost digital sensor for measuring temperature and humidity. This tutorial shows you how to connect the DHT11 to an Arduino and write code to read and display humidity values in real time.

Required Components

No Ads Available.

Wiring Diagram

Connect the DHT11 sensor as follows:

Arduino Code


#include 

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();

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

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print("%  Temperature: ");
    Serial.print(temperature);
    Serial.println("°C");

    delay(2000);
}
            

Upload this code to your Arduino and open the Serial Monitor to see humidity and temperature readings every 2 seconds.

Applications

Conclusion

With the DHT11 sensor, you can easily monitor humidity and temperature in various environments. Experiment with adding displays or sending data to a server for advanced projects!

Contact Us

If you have any questions or inquiries, feel free to reach out to us at Microautomation.no@icloud.com .

Follow our Socials for the newest updates!