/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: DHT22 Monitor
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2024-08-06 12:05:36
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Hőmérséklet- és páratartalom-ellenőrző rendszert */
/* valósítson meg a D4 digitális érintkezőhöz */
/* csatlakoztatott DHT22 érzékelővel. Biztosítsa a */
/* pontos leolvasásokat, és kecsesen kezelje az */
/* esetleges érzékelőhibákat. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/adafruit/DHT-sensor-library
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t dht_DHT22_DOUT_PIN_D4 = 4; // Define the pin for DHT22 sensor
/***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the DHT class for the DHT22 sensor
DHT dht(dht_DHT22_DOUT_PIN_D4, DHT22); // Initialize DHT sensor on pin D4
void setup(void)
{
// Initialize serial communication at 9600 baud
Serial.begin(9600);
dht.begin(); // Initialize the DHT sensor
}
void loop(void)
{
// Wait a few seconds between measurements
delay(2000);
// Read temperature as Celsius
float temperature = dht.readTemperature();
if (isnan(temperature)) {
// Handle the case where the temperature reading failed
Serial.println(F("Failed to read temperature from DHT sensor!"));
} else {
// Print the temperature value
Serial.print(F("Temperature: "));
Serial.print(temperature);
Serial.println(F("°C"));
}
// Read humidity
float humidity = dht.readHumidity();
if (isnan(humidity)) {
// Handle the case where the humidity reading failed
Serial.println(F("Failed to read humidity from DHT sensor!"));
} else {
// Print the humidity value
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.println(F("%"));
}
}
/* END CODE */