Created DHT11 sensor library

This commit is contained in:
Dhruba Saha
2023-05-30 18:28:45 +05:30
parent 39b3dd62d1
commit 323e8c192b
7 changed files with 271 additions and 1 deletions

View File

@ -0,0 +1,32 @@
#include <DHT11.h>
// Create an instance of the DHT11 class and set the digital I/O pin.
DHT11 dht11(2);
void setup()
{
// Initialize serial communication at 115200 baud.
Serial.begin(115200);
}
void loop()
{
// Read the humidity from the sensor.
float humidity = dht11.readHumidity();
// If the humidity reading was successful, print it to the serial monitor.
if (humidity != -1)
{
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
else
{
// If the humidity reading failed, print an error message.
Serial.println("Error reading humidity");
}
// Wait for 2 seconds before the next reading.
delay(2000);
}