Advertisement
pleasedontcode

Temperature Control rev_01

Apr 19th, 2024
57
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: Temperature Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-19 17:43:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measure temperature using DS18B20 sensor every */
  21.     /* 10s. Display temperature. If temp > 37°C, turn off */
  22.     /* heater. If temp <= 37°C, turn on heater. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <OneWire.h>
  27. #include <DallasTemperature.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  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. bool Heater_LED_PIN_D2_rawData = 0;
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. float Heater_LED_PIN_D2_phyData = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D3);
  48. DallasTemperature sensors(&oneWire);
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.  
  54.   pinMode(Temp_sensor_DS18B20_DQ_PIN_D3, INPUT);
  55.  
  56.   pinMode(Heater_LED_PIN_D2, OUTPUT);
  57.  
  58.   sensors.begin();
  59.   sensors.setResolution(12);
  60. }
  61.  
  62. void loop(void)
  63. {
  64.   // put your main code here, to run repeatedly:
  65.  
  66.   sensors.requestTemperatures(); // Read temperature from DS18B20 sensor
  67.  
  68.   float temperature = sensors.getTempCByIndex(0);
  69.  
  70.   // Update Heater LED based on temperature
  71.   if (temperature > 37) {
  72.     Heater_LED_PIN_D2_rawData = LOW; // Turn off heater
  73.   } else {
  74.     Heater_LED_PIN_D2_rawData = HIGH; // Turn on heater
  75.   }
  76.  
  77.   updateOutputs(); // Refresh output data
  78.  
  79.   delay(10000); // Delay for 10 seconds
  80. }
  81.  
  82. void updateOutputs(void)
  83. {
  84.   digitalWrite(Heater_LED_PIN_D2, Heater_LED_PIN_D2_rawData);
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement