Advertisement
pleasedontcode

"Heat Control" rev_01

Feb 11th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Heat Control"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-02-11 10:35:13
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on when set temperature reached */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t heat_DS18B20_DQ_PIN_D4 = 4;
  32. const uint8_t HEAT_PIN = 5; // Replace with the actual pin number for the heat pin
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. DS18B20 ds(heat_DS18B20_DQ_PIN_D4);
  36.  
  37. /****** SYSTEM REQUIREMENTS *****/
  38. /****** SYSTEM REQUIREMENT 1 *****/
  39. /* turn on when set temperature reached */
  40. bool isTemperatureReached(float setTemperature, float currentTemperature)
  41. {
  42.     return currentTemperature >= setTemperature;
  43. }
  44. /****** END SYSTEM REQUIREMENTS *****/
  45.  
  46. void setup(void)
  47. {
  48.     // put your setup code here, to run once:
  49.     pinMode(heat_DS18B20_DQ_PIN_D4, INPUT);
  50.     pinMode(HEAT_PIN, OUTPUT); // Set the heat pin as output
  51.  
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     float setTemperature = 25.0; // Set temperature in degrees Celsius
  58.  
  59.     // Read current temperature
  60.     float currentTemperature = ds.getTempC();
  61.  
  62.     // Check if set temperature is reached
  63.     if (isTemperatureReached(setTemperature, currentTemperature))
  64.     {
  65.         // Add code here to turn on the desired device or trigger an action
  66.         // For example, you can use digitalWrite() to turn on a pin connected to a device
  67.         digitalWrite(HEAT_PIN, HIGH);
  68.     }
  69.  
  70.     delay(1000); // Delay for 1 second before checking the temperature again
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement