/********* 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 Reading**
- Source Code NOT compiled for: ESP8266 NodeMCU V1.0
- Source Code created on: 2024-11-18 00:51:26
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The project aims to develop an Arduino-based */
/* system utilizing specific libraries for sensor */
/* integration and data processing, ensuring */
/* efficient communication and control of connected */
/* components. */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/****** GLOBAL VARIABLES *****/
DHT dht(2, DHT22); // Initialize DHT sensor on pin 2 with DHT22 model
void setup(void)
{
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize DHT sensor
dht.begin();
}
void loop(void)
{
// Read temperature and humidity values from DHT sensor
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
// Wait a few seconds between measurements
delay(2000);
}
/* END CODE */