Measuring Temperature and Humidity using DHT11:

Component list:
1. DTH11 Temp/Humidity Sensor
2. 4K7 Resistor
3. Arduino UNO




Data pin of the Sensor can be connected to any digital pin of the UNO.
Also needs to pull up data pin with 4K7 resistor.
DTH11 can be powered from the UNO board.
connect the board to USB through to the computer.

Launch Arduino IDE, from Library manager, install Adafruit DHT sensor Library.




Arduino code:

//Example testing sketch for DHT11/22 sensors
// DHT Sensor Library:  https://github.com/adafruit/DHT-sensor-library
//AMP technology @ 2021
#include "DHT.h"
#define DHTPIN 7     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11   // DHT11 Sensor
// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
   Serial.begin(9600);
   Serial.println(“DTH11 Sett up”);
   dht.begin();  
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
//read Humidity  
  float h = dht.readHumidity();
// Read temperature as Celsius (the default)
  float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
  }
  Serial.println("Humidity: ");
  Serial.print(h);
  Serial.println("Temperature: ");
  Serial.print(t);
  Serial.print("°C ")
}




0Comments

For Comment you need to Login