#include <DHT.h>
// Define the pin where the DHT22 data pin is connected
#define DHTPIN 16
// Define the type of sensor you're using
#define DHTTYPE DHT22
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize serial communication at 9600 baud rate
Serial.begin(9600);
Serial.print("Temperature: ");
//Serial.print(tempC);
//Serial.println(" °C");
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read the temperature in Celsius
float tempC = dht.readTemperature();
// Check if any reads failed and exit early (to try again)
if (isnan(tempC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println(" °C");
}