Advertisement
pleasedontcode

Temperature Monitoring rev_01

Oct 8th, 2024
74
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 Monitoring
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-08 20:23:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall utilize the DS18B20 temperature */
  21.     /* sensor to monitor temperature readings via digital */
  22.     /* pin D2, ensuring accurate data collection for */
  23.     /* environmental monitoring applications. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t hamza_DS18B20_DQ_PIN_D2       = 2; // Define the digital pin for the DS18B20 sensor
  35.  
  36. // Define alarm thresholds
  37. #define LOW_ALARM 20
  38. #define HIGH_ALARM 25
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. // Create an instance of the DS18B20 class
  42. DS18B20 ds(hamza_DS18B20_DQ_PIN_D2); // Initialize the DS18B20 object with the data pin
  43.  
  44. // Define the address of the DS18B20 sensor (example address)
  45. uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52}; // Moved outside of functions for reuse
  46.  
  47. void setup(void)
  48. {
  49.     // Start the serial communication
  50.     Serial.begin(9600);
  51.    
  52.     // Select the DS18B20 sensor using its address
  53.     if (ds.select(address)) {
  54.         // Set alarm thresholds for the sensor
  55.         ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  56.     } else {
  57.         Serial.println("Device not found!"); // Print error if device is not found
  58.     }
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // Check if the DS18B20 sensor is selected
  64.     if (ds.select(address)) {
  65.         // Check if there is an alarm condition
  66.         if (ds.hasAlarm()) {
  67.             // Print a warning message with the current temperature
  68.             Serial.print("Warning! Temperature is ");
  69.             Serial.print(ds.getTempC());
  70.             Serial.println(" C");
  71.         }
  72.     } else {
  73.         Serial.println("Device not found!"); // Print error if device is not found
  74.     }
  75.  
  76.     // Wait for 10 seconds before the next loop iteration
  77.     delay(10000);
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement