Advertisement
pleasedontcode

Temperature Control rev_01

Apr 20th, 2024
59
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-20 14:54:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measure temperature using DS18B20 sensor every */
  21.     /* 10s. Display temperature on serial monitor. */
  22.     /* Control heater based on temperature. Turn off */
  23.     /* heater if temperature >= 37°C. Turn on heater if */
  24.     /* temperature < 37°C. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <OneWire.h> // https://github.com/PaulStoffregen/OneWire
  29. #include <DallasTemperature.h> // https://github.com/milesburton/Arduino-Temperature-Control-Library
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t Temp_sensor_DS18B20_DQ_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t Heater_LED_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool Heater_LED_PIN_D3_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float Heater_LED_PIN_D3_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D2); // Create an instance of the OneWire class
  52. DallasTemperature sensors(&oneWire); // Pass the OneWire instance to the DallasTemperature library
  53.  
  54. void setup(void)
  55. {
  56.   // put your setup code here, to run once:
  57.  
  58.   pinMode(Temp_sensor_DS18B20_DQ_PIN_D2, INPUT);
  59.  
  60.   pinMode(Heater_LED_PIN_D3, OUTPUT);
  61.  
  62.   Serial.begin(9600);
  63.  
  64.   sensors.begin(); // Initialize the DallasTemperature library
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   sensors.requestTemperatures(); // Send the command to get temperatures
  72.   float temperatureC = sensors.getTempCByIndex(0); // Read the temperature in Celsius
  73.  
  74.   // Display temperature on serial monitor
  75.   Serial.print("Temperature: ");
  76.   Serial.print(temperatureC);
  77.   Serial.println("°C");
  78.  
  79.   // Control heater based on temperature
  80.   if (temperatureC >= 37.0)
  81.   {
  82.     Heater_LED_PIN_D3_rawData = LOW; // Turn off heater
  83.   }
  84.   else
  85.   {
  86.     Heater_LED_PIN_D3_rawData = HIGH; // Turn on heater
  87.   }
  88.  
  89.   updateOutputs(); // Refresh output data
  90.  
  91.   delay(10000); // Wait for 10 seconds before measuring again
  92. }
  93.  
  94. void updateOutputs()
  95. {
  96.   digitalWrite(Heater_LED_PIN_D3, Heater_LED_PIN_D3_rawData);
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement