CCCPaste

Temperature Display rev_06

/********* 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: Temperature Display
	- Source Code NOT compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-05-16 14:05:53

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* read temperatura and print on serial */
/****** 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 TemperatureSensor_DHT22_DOUT_PIN_D4 = 4;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
DHT dht(TemperatureSensor_DHT22_DOUT_PIN_D4, DHT22);

void setup(void)
{
	// put your setup code here, to run once:
	Serial.begin(9600);
	dht.begin();
}

void loop(void)
{
	// put your main code here, to run repeatedly:
	delay(dht.getMinimumSamplingPeriod());

	sensors_event_t event;
	dht.temperature().getEvent(&event);
	if (isnan(event.temperature)) {
		Serial.println(F("Error reading temperature!"));
	} else {
		Serial.print(F("Temperature: "));
		Serial.print(event.temperature);
		Serial.println(F("°C"));
	}

	dht.humidity().getEvent(&event);
	if (isnan(event.relative_humidity)) {
		Serial.println(F("Error reading humidity!"));
	} else {
		Serial.print(F("Humidity: "));
		Serial.print(event.relative_humidity);
		Serial.println(F("%"));
	}
}