Advertisement
pleasedontcode

Temperature Control rev_02

Apr 20th, 2024
66
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 09:07:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Use a DS18B20 sensor to measure temperature and */
  21.     /* display it every 10 seconds and use a heater. If */
  22.     /* the temperature is >= 37 turn off the heater and */
  23.     /* if it’s < 37 turn on the heater. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - please use a different library
  30. ********* User code review feedback **********/
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <OneWire.h>
  34. #include <DallasTemperature.h>
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. void updateOutputs(void);
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t Temp_sensor_DS18B20_DQ_PIN_D2 = 2;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t Heater_LED_PIN_D3 = 3;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. bool Heater_LED_PIN_D3_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float Heater_LED_PIN_D3_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D2);
  57. DallasTemperature ds18b20(&oneWire);
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.     Serial.begin(9600);
  63.  
  64.     ds18b20.begin();
  65.  
  66.     uint8_t address[] = {0x28, 0xFF, 0x28, 0x9C, 0x71, 0x17, 0x03, 0x8E}; // Replace with your DS18B20 sensor address
  67.     ds18b20.setLowAlarmTemp(address, 37); // Set low alarm temperature to 37 degrees
  68.     ds18b20.setHighAlarmTemp(address, 37); // Set high alarm temperature to 37 degrees
  69.     ds18b20.setResolution(address, 12); // Set the resolution of the sensor
  70.  
  71.     pinMode(Heater_LED_PIN_D3, OUTPUT);
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // put your main code here, to run repeatedly:
  77.     ds18b20.requestTemperatures(); // Read temperature values
  78.  
  79.     float temperature = ds18b20.getTempCByIndex(0); // Get temperature in Celsius
  80.     Serial.print("Temperature: ");
  81.     Serial.print(temperature);
  82.     Serial.println(" C");
  83.  
  84.     if (temperature >= 37) {
  85.         // Turn off the heater
  86.         Heater_LED_PIN_D3_rawData = 0;
  87.         updateOutputs();
  88.     } else {
  89.         // Turn on the heater
  90.         Heater_LED_PIN_D3_rawData = 1;
  91.         updateOutputs();
  92.     }
  93.  
  94.     delay(10000);
  95. }
  96.  
  97. void updateOutputs()
  98. {
  99.     digitalWrite(Heater_LED_PIN_D3, Heater_LED_PIN_D3_rawData);
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement