Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-21 15:32:45
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The thermostat maintains the set temperature for */
- /* the specified time. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> // https://github.com/matmunk/DS18B20
- #include <OneWire.h> // Required for DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_Sensor_DS18B20_DQ_PIN_D4 = 4; // Data pin for DS18B20
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- OneWire oneWire(Temp_Sensor_DS18B20_DQ_PIN_D4); // Create OneWire instance
- DS18B20 sensor(&oneWire); // Create DS18B20 instance
- // Desired temperature and time
- const float setTemperature = 25.0; // Set temperature in Celsius
- const unsigned long holdTime = 60000; // Hold time in milliseconds (60 seconds)
- unsigned long previousMillis = 0; // Store last time temperature was set
- bool temperatureMaintained = false; // Flag to check if temperature is maintained
- void setup(void)
- {
- Serial.begin(115200); // Initialize serial communication
- sensor.begin(); // Initialize DS18B20 sensor
- }
- void loop(void)
- {
- // Request temperature from the sensor
- sensor.requestTemperatures();
- float currentTemperature = sensor.getTempC(); // Get current temperature
- // Check if the current temperature is below the set temperature
- if (currentTemperature < setTemperature && !temperatureMaintained) {
- Serial.println("Heating up to set temperature..."); // Debug message
- // Here, you would add code to turn on the heater (not implemented)
- }
- else if (currentTemperature >= setTemperature) {
- // If the temperature is reached, start the timer
- if (!temperatureMaintained) {
- previousMillis = millis(); // Reset timer
- temperatureMaintained = true; // Set flag to true
- Serial.println("Set temperature reached, maintaining..."); // Debug message
- }
- // Check if the hold time has elapsed
- if (millis() - previousMillis >= holdTime) {
- // Here, you would add code to turn off the heater (not implemented)
- Serial.println("Hold time elapsed, turning off heater."); // Debug message
- temperatureMaintained = false; // Reset flag
- }
- }
- // Print current temperature to serial monitor
- Serial.print("Current Temperature: ");
- Serial.println(currentTemperature);
- delay(1000); // Delay to avoid flooding the serial output
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement