Advertisement
pleasedontcode

Temperature Controller rev_03

Apr 20th, 2024
52
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 Controller
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-20 08:06:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop an Arduino code using DS18B20 sensor to */
  21.     /* measure temperature every 10s. Display temperature */
  22.     /* on serial monitor. Implement a heater. If */
  23.     /* temperature is >= 37°C, turn off the heater. If */
  24.     /* temperature is < 37°C, turn on the heater. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Develop an Arduino code using DS18B20 sensor to */
  27.     /* measure temperature every 10s. Display temperature */
  28.     /* on serial monitor. Implement a heater. If */
  29.     /* temperature is >= 37°C, turn off the heater. If */
  30.     /* temperature is < 37°C, turn on the heater. */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <DS18B20.h> //https://github.com/matmunk/DS18B20
  35.  
  36. /****** SYSTEM REQUIREMENTS *****/
  37. /****** SYSTEM REQUIREMENT 1 *****/
  38. /* Develop an Arduino code using DS18B20 sensor to */
  39. /* measure temperature every 10s. Display temperature */
  40. /* on serial monitor. Implement a heater. If */
  41. /* temperature is >= 37°C, turn off the heater. If */
  42. /* temperature is < 37°C, turn on the heater. */
  43.  
  44. /****** FUNCTION PROTOTYPES *****/
  45. void setup(void);
  46. void loop(void);
  47. void updateOutputs(void);
  48.  
  49. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  50. const uint8_t Temp_sensor_DS18B20_DQ_PIN_D2 = 2;
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t Heater_LED_PIN_D3 = 3;
  54.  
  55. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  56. /***** used to store raw data *****/
  57. bool Heater_LED_PIN_D3_rawData = 0;
  58.  
  59. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  60. /***** used to store data after characteristic curve transformation *****/
  61. float Heater_LED_PIN_D3_phyData = 0.0;
  62.  
  63. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  64. DS18B20 ds(Temp_sensor_DS18B20_DQ_PIN_D2);
  65.  
  66. void setup(void)
  67. {
  68.   // put your setup code here, to run once:
  69.  
  70.   pinMode(Temp_sensor_DS18B20_DQ_PIN_D2, INPUT);
  71.   pinMode(Heater_LED_PIN_D3, OUTPUT);
  72.  
  73.   Serial.begin(9600);
  74. }
  75.  
  76. void loop(void)
  77. {
  78.   // put your main code here, to run repeatedly:
  79.  
  80.   // Read temperature from DS18B20 sensor
  81.   float temperature = ds.getTempC();
  82.  
  83.   // Display temperature on serial monitor
  84.   Serial.print("Temperature: ");
  85.   Serial.print(temperature);
  86.   Serial.println(" °C");
  87.  
  88.   // Control the heater based on temperature
  89.   if (temperature >= 37.0)
  90.   {
  91.     Heater_LED_PIN_D3_rawData = 0; // Turn off the heater
  92.   }
  93.   else
  94.   {
  95.     Heater_LED_PIN_D3_rawData = 1; // Turn on the heater
  96.   }
  97.  
  98.   updateOutputs(); // Refresh output data
  99.  
  100.   delay(10000); // Wait for 10 seconds
  101. }
  102.  
  103. void updateOutputs()
  104. {
  105.   digitalWrite(Heater_LED_PIN_D3, Heater_LED_PIN_D3_rawData);
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement