Advertisement
pleasedontcode

Temp Control rev_01

Oct 21st, 2024
75
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: Temp Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-21 05:40:41
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* If DUT temperature is less than 50°C & POT voltage */
  21.     /* is less than 2 Volts starts output connected to */
  22.     /* pin3 else no output */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t TC1_DS18B20_DQ_PIN_D2     = 2; // Pin for DS18B20 data line
  34. const uint8_t TC1_DS18B20_DQ_PIN_D3     = 3; // Output pin for control
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Create an instance of the DS18B20 class, using pin D2
  38. DS18B20 ds(TC1_DS18B20_DQ_PIN_D2);
  39.  
  40. // Define alarm temperature thresholds
  41. #define LOW_ALARM 20
  42. #define HIGH_ALARM 25
  43.  
  44. // Address of the DS18B20 device (example address)
  45. uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
  46.  
  47. /****** SETUP FUNCTION *****/
  48. void setup(void)
  49. {
  50.     // Start serial communication for debugging
  51.     Serial.begin(9600);
  52.  
  53.     // Set pin modes for the digital input pins
  54.     pinMode(TC1_DS18B20_DQ_PIN_D2, INPUT);
  55.     pinMode(TC1_DS18B20_DQ_PIN_D3, OUTPUT); // Set pin D3 as output
  56.  
  57.     // Select the DS18B20 device using its address
  58.     if (ds.select(address)) {
  59.         // Set the alarm thresholds for the temperature sensor
  60.         ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  61.     } else {
  62.         Serial.println("Device not found!");
  63.     }
  64. }
  65.  
  66. /****** LOOP FUNCTION *****/
  67. void loop(void)
  68. {
  69.     // Check if the DS18B20 device is selected
  70.     if (ds.select(address)) {
  71.         // Get the current temperature
  72.         float currentTemperature = ds.getTempC();
  73.        
  74.         // Simulate reading POT voltage (replace with actual voltage reading code)
  75.         float potVoltage = analogRead(A0) * (5.0 / 1023.0); // Assuming a 5V reference
  76.  
  77.         // Check the system requirements
  78.         if (currentTemperature < 50.0 && potVoltage < 2.0) {
  79.             digitalWrite(TC1_DS18B20_DQ_PIN_D3, HIGH); // Activate output
  80.         } else {
  81.             digitalWrite(TC1_DS18B20_DQ_PIN_D3, LOW); // Deactivate output
  82.         }
  83.  
  84.         // Check if the temperature alarm has been triggered
  85.         if (ds.hasAlarm()) {
  86.             // Print a warning message with the current temperature
  87.             Serial.print("Warning! Temperature is ");
  88.             Serial.print(currentTemperature);
  89.             Serial.println(" C");
  90.         }
  91.     } else {
  92.         Serial.println("Device not found!");
  93.     }
  94.  
  95.     // Wait for 10 seconds before the next loop iteration
  96.     delay(10000);
  97. }
  98.  
  99. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement