Advertisement
pleasedontcode

Temperature Control rev_01

May 11th, 2024
1,173
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 NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-11 16:58:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Use a D518820 sensor to measure temperature every */
  21.     /* 10 seconds and use a heater. the temperature is > */
  22.     /* 37 turn off the heater and if it's < 37 turn on */
  23.     /* the heater. Display the current temperature on the */
  24.     /* serial monitor. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <MaximWire.h>
  29. #include <DS18B20.h> //https://github.com/matmunk/DS18B20
  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 tms_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. MaximWire::Bus bus(9); // Define the MaximWire bus on pin 9
  52. MaximWire::DS18B20 device; // Define the DS18B20 device
  53.  
  54. void setup(void)
  55. {
  56.     // put your setup code here, to run once:
  57.     Serial.begin(9600);
  58.  
  59.     pinMode(tms_DS18B20_DQ_PIN_D2, INPUT);
  60.     pinMode(heater_LED_PIN_D3, OUTPUT);
  61.  
  62.     // Initialize the DS18B20 device
  63.     device = MaximWire::DS18B20(bus.Discover().FindNextDevice().GetAddress());
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // put your main code here, to run repeatedly:
  69.     // Measure temperature every 10 seconds
  70.     device.requestTemperatures();
  71.     float temperature = device.getTempCByIndex(0);
  72.  
  73.     // Control the heater based on temperature
  74.     if (temperature > 37) {
  75.         heater_LED_PIN_D3_rawData = LOW; // Turn off the heater
  76.     } else {
  77.         heater_LED_PIN_D3_rawData = HIGH; // Turn on the heater
  78.     }
  79.  
  80.     updateOutputs(); // Refresh output data
  81.  
  82.     // Display the current temperature on the serial monitor
  83.     Serial.print("Temperature: ");
  84.     Serial.print(temperature);
  85.     Serial.println(" C");
  86.  
  87.     delay(10000); // Wait for 10 seconds
  88. }
  89.  
  90. void updateOutputs()
  91. {
  92.     digitalWrite(heater_LED_PIN_D3, heater_LED_PIN_D3_rawData);
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement