Advertisement
pleasedontcode

Temperature Control rev_02

Apr 19th, 2024
72
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:50:09
  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.  
  26. /********* User code review feedback **********
  27. #### Feedback 1 ####
  28. - i need the temperature to be displayed on the serial monitor
  29. ********* User code review feedback **********/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <OneWire.h>
  33. #include <DallasTemperature.h>
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38. void updateOutputs(void);
  39.  
  40. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  41. const uint8_t Temp_sensor_DS18B20_DQ_PIN_D3 = 3;
  42.  
  43. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  44. const uint8_t Heater_LED_PIN_D2 = 2;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. bool Heater_LED_PIN_D2_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. float Heater_LED_PIN_D2_phyData = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D3);
  54. DallasTemperature sensors(&oneWire);
  55.  
  56. void setup(void)
  57. {
  58.   // Initialize serial communication
  59.   Serial.begin(9600);
  60.  
  61.   // Configure input and output pins
  62.   pinMode(Temp_sensor_DS18B20_DQ_PIN_D3, INPUT);
  63.   pinMode(Heater_LED_PIN_D2, OUTPUT);
  64.  
  65.   // Initialize DS18B20 sensor
  66.   sensors.begin();
  67.   sensors.setResolution(12);
  68. }
  69.  
  70. void loop(void)
  71. {
  72.   // Read temperature from DS18B20 sensor
  73.   sensors.requestTemperatures();
  74.   float temperature = sensors.getTempCByIndex(0);
  75.  
  76.   // Display temperature on the serial monitor
  77.   Serial.print("Temperature: ");
  78.   Serial.print(temperature);
  79.   Serial.println("°C");
  80.  
  81.   // Update Heater LED based on temperature
  82.   if (temperature > 37) {
  83.     Heater_LED_PIN_D2_rawData = LOW; // Turn off heater
  84.   } else {
  85.     Heater_LED_PIN_D2_rawData = HIGH; // Turn on heater
  86.   }
  87.  
  88.   updateOutputs(); // Refresh output data
  89.  
  90.   delay(10000); // Delay for 10 seconds
  91. }
  92.  
  93. void updateOutputs(void)
  94. {
  95.   digitalWrite(Heater_LED_PIN_D2, Heater_LED_PIN_D2_rawData);
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement