Advertisement
pleasedontcode

"Heater Control" rev_01

Apr 20th, 2024
77
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: "Heater Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-20 14:25:37
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measure temperature using DS18B20 sensor every */
  21.     /* 10s. Control heater based on temperature. Turn off */
  22.     /* heater if temperature > 37°C, turn on if <= 37°C. */
  23.     /* Display temperature on serial monitor. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <DS18B20.h>    // Include the DS18B20 library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void); // Add the function prototype for updateOutputs()
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t Temp_sensor_DS18B20_DQ_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t Heater_LED_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool Heater_LED_PIN_D2_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float Heater_LED_PIN_D2_phyData = 0.0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. DS18B20 ds18b20(Temp_sensor_DS18B20_DQ_PIN_D3); // Create an instance of the DS18B20 library
  50.  
  51. void setup(void)
  52. {
  53.     // put your setup code here, to run once:
  54.     pinMode(Temp_sensor_DS18B20_DQ_PIN_D3, INPUT);
  55.     pinMode(Heater_LED_PIN_D2, OUTPUT);
  56.     Serial.begin(9600); // Initialize serial communication
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // put your main code here, to run repeatedly:
  62.     float temperature = ds18b20.getTempC(); // Get temperature from DS18B20 sensor
  63.  
  64.     // Control heater based on temperature
  65.     if (temperature > 37)
  66.     {
  67.         Heater_LED_PIN_D2_rawData = 0; // Turn off heater
  68.     }
  69.     else
  70.     {
  71.         Heater_LED_PIN_D2_rawData = 1; // Turn on heater
  72.     }
  73.  
  74.     // Display temperature on serial monitor
  75.     Serial.print("Temperature: ");
  76.     Serial.print(temperature);
  77.     Serial.println(" C");
  78.  
  79.     updateOutputs(); // Refresh output data
  80.  
  81.     delay(10000); // Wait for 10 seconds
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.     digitalWrite(Heater_LED_PIN_D2, Heater_LED_PIN_D2_rawData);
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement