November 21, 2024

DHT11

DHT11 needs a simple circuit. Refer the above diagram. The code is below

#define DHT11PIN 7

dht11 DHT11;

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

void loop()
{
  Serial.println();

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);

  delay(2000);

}

To change DHT11 temperature to Fahrenheit use the formula 
double far = (DHT11.temperature * (9 /5)) + 32

To see the temp and humidity on the serial monitor , on the Arduino  IDE goto tools > Serial Monitor

You should see the current temp and humidity on the serial monitor.