Dasturni fumksional tugmalari
#include // Include the DHT sensor library
#define DHTPIN 2 // Define the digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // Define the type of DHT sensor you are using
DHT dht(DHTPIN, DHTTYPE); // Create a DHT object
void setup() {
Serial.begin(9600); // Initialize serial communication for displaying the readings
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Delay for 2 seconds
float humidity = dht.readHumidity(); // Read humidity value from the sensor
float temperature = dht.readTemperature(); // Read temperature value from the sensor in Celsius
// Check if any reading failed
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the humidity and temperature values
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("°C");
}