Advertisement
pleasedontcode

Temperature Controller rev_04

Apr 20th, 2024
78
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:15:27
  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.  
  34. /********* User code review feedback **********
  35. #### Feedback 1 ####
  36. - try use a different library
  37.  
  38. ********* User code review feedback **********/
  39.  
  40. /****** DEFINITION OF LIBRARIES *****/
  41. #include <OneWire.h>
  42. #include <DallasTemperature.h>
  43.  
  44. /****** SYSTEM REQUIREMENTS *****/
  45. /****** SYSTEM REQUIREMENT 1 *****/
  46. /* Develop an Arduino code using DS18B20 sensor to */
  47. /* measure temperature every 10s. Display temperature */
  48. /* on serial monitor. Implement a heater. If */
  49. /* temperature is >= 37°C, turn off the heater. If */
  50. /* temperature is < 37°C, turn on the heater. */
  51.  
  52. /****** FUNCTION PROTOTYPES *****/
  53. void setup(void);
  54. void loop(void);
  55. void updateOutputs(void);
  56.  
  57. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  58. const uint8_t Temp_sensor_DS18B20_DQ_PIN = 2;
  59.  
  60. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  61. const uint8_t Heater_LED_PIN = 3;
  62.  
  63. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  64. /***** used to store raw data *****/
  65. bool Heater_LED_PIN_rawData = 0;
  66.  
  67. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  68. /***** used to store data after characteristic curve transformation *****/
  69. float Heater_LED_PIN_phyData = 0.0;
  70.  
  71. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  72. OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN);
  73. DallasTemperature sensors(&oneWire);
  74.  
  75. void setup(void)
  76. {
  77.   // put your setup code here, to run once:
  78.  
  79.   sensors.begin();
  80.  
  81.   pinMode(Heater_LED_PIN, OUTPUT);
  82.  
  83.   Serial.begin(9600);
  84. }
  85.  
  86. void loop(void)
  87. {
  88.   // put your main code here, to run repeatedly:
  89.  
  90.   sensors.requestTemperatures();
  91.  
  92.   // Read temperature from DS18B20 sensor
  93.   float temperature = sensors.getTempCByIndex(0);
  94.  
  95.   // Display temperature on serial monitor
  96.   Serial.print("Temperature: ");
  97.   Serial.print(temperature);
  98.   Serial.println(" °C");
  99.  
  100.   // Control the heater based on temperature
  101.   if (temperature >= 37.0)
  102.   {
  103.     Heater_LED_PIN_rawData = 0; // Turn off the heater
  104.   }
  105.   else
  106.   {
  107.     Heater_LED_PIN_rawData = 1; // Turn on the heater
  108.   }
  109.  
  110.   updateOutputs(); // Refresh output data
  111.  
  112.   delay(10000); // Wait for 10 seconds
  113. }
  114.  
  115. void updateOutputs()
  116. {
  117.   digitalWrite(Heater_LED_PIN, Heater_LED_PIN_rawData);
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement