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: "Thermostat Control"
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-21 15:34:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The thermostat maintains the set temperature for */
- /* the specified time. rtos is used */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <OneWire.h> // Include OneWire library for DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void thermostatTask(void *pvParameters); // Task function for the thermostat
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_Sensor_DS18B20_DQ_PIN_D4 = 4;
- /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- OneWire oneWire(Temp_Sensor_DS18B20_DQ_PIN_D4); // Create OneWire instance
- DS18B20 tempSensor(&oneWire); // Create DS18B20 instance
- // Temperature settings
- float setTemperature = 25.0; // Desired temperature in Celsius
- const int holdTime = 60000; // Time to maintain temperature in milliseconds
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- // Initialize temperature sensor
- if (!tempSensor.begin()) {
- Serial.println("Could not find a valid DS18B20 sensor at the pin.");
- while (1);
- }
- // Create a FreeRTOS task for the thermostat
- xTaskCreate(thermostatTask, "ThermostatTask", 2048, NULL, 1, NULL);
- }
- void loop(void)
- {
- // Main loop can be used for other tasks or can remain empty
- }
- /****** THERMOSTAT TASK FUNCTION *****/
- void thermostatTask(void *pvParameters)
- {
- while (true) {
- // Request temperature from the sensor
- tempSensor.requestTemperatures();
- float currentTemperature = tempSensor.getTempC();
- // Print the current temperature
- Serial.print("Current Temperature: ");
- Serial.println(currentTemperature);
- // Check if the current temperature is below the set temperature
- if (currentTemperature < setTemperature) {
- // Code to turn on heating (e.g., digitalWrite(HEATER_PIN, HIGH);)
- Serial.println("Heating ON");
- } else {
- // Code to turn off heating (e.g., digitalWrite(HEATER_PIN, LOW);)
- Serial.println("Heating OFF");
- }
- // Maintain the set temperature for the specified time
- vTaskDelay(holdTime / portTICK_PERIOD_MS); // Delay for holdTime
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement