CCCPaste

Sensor Readings rev_01

/********* 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: Sensor Readings
	- Source Code compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-02-27 09:05:22

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* print tempature value in serial monitor */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include "DHT.h"

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t dht_DHT11_DOUT_PIN_D4 = 4;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
DHT dht(dht_DHT11_DOUT_PIN_D4, DHT11); // Create DHT object

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(dht_DHT11_DOUT_PIN_D4, INPUT_PULLUP);
    dht.begin(); // Initialize DHT sensor

    // Add any other setup code here
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    // Read temperature and humidity from DHT sensor
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    // Check if temperature and humidity values are valid
    if (isnan(temperature) || isnan(humidity))
    {
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
    }

    // Print temperature and humidity values to serial monitor
    Serial.print(F("Temperature: "));
    Serial.print(temperature);
    Serial.print(F("°C, Humidity: "));
    Serial.print(humidity);
    Serial.println(F("%"));

    // Add your code to process temperature and humidity values

    delay(2000); // Delay for 2 seconds before next reading
}