/********* 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 Control - Source Code compiled for: ESP32 DevKit V1 - Source Code created on: 2024-02-14 14:05:25 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* if user selects heat mode , turn on rely which */ /* turns on peltier. Maintain temperature at 60 deg */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Temp_DHT11_DOUT_PIN_D4 = 4; const uint8_t HEAT_RELAY_PIN = 5; // Pin number for heat relay control /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ DHT dht(Temp_DHT11_DOUT_PIN_D4, DHT11); /****** SYSTEM REQUIREMENTS *****/ const float targetTemperature = 60.0; // Target temperature in degrees Celsius void setup(void) { // put your setup code here, to run once: pinMode(Temp_DHT11_DOUT_PIN_D4, INPUT_PULLUP); pinMode(HEAT_RELAY_PIN, OUTPUT); digitalWrite(HEAT_RELAY_PIN, LOW); // Start with heat relay off dht.begin(); } void loop(void) { // put your main code here, to run repeatedly: float temperature = dht.readTemperature(); // Check if read failed and exit early (to try again). if (isnan(temperature)) { Serial.println("Failed to read temperature from DHT sensor!"); return; } // Print temperature value. Serial.print("Temperature: "); Serial.print(temperature); Serial.print(" °C\t"); // Check if temperature is below target temperature and turn on relay if true. if (temperature < targetTemperature) { digitalWrite(HEAT_RELAY_PIN, HIGH); } else { digitalWrite(HEAT_RELAY_PIN, LOW); } delay(2000); // Wait for 2 seconds before next reading. }