Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Temperature Monitoring
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-08 20:23:03
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize the DS18B20 temperature */
- /* sensor to monitor temperature readings via digital */
- /* pin D2, ensuring accurate data collection for */
- /* environmental monitoring applications. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t hamza_DS18B20_DQ_PIN_D2 = 2; // Define the digital pin for the DS18B20 sensor
- // Define alarm thresholds
- #define LOW_ALARM 20
- #define HIGH_ALARM 25
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the DS18B20 class
- DS18B20 ds(hamza_DS18B20_DQ_PIN_D2); // Initialize the DS18B20 object with the data pin
- // Define the address of the DS18B20 sensor (example address)
- uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52}; // Moved outside of functions for reuse
- void setup(void)
- {
- // Start the serial communication
- Serial.begin(9600);
- // Select the DS18B20 sensor using its address
- if (ds.select(address)) {
- // Set alarm thresholds for the sensor
- ds.setAlarms(LOW_ALARM, HIGH_ALARM);
- } else {
- Serial.println("Device not found!"); // Print error if device is not found
- }
- }
- void loop(void)
- {
- // Check if the DS18B20 sensor is selected
- if (ds.select(address)) {
- // Check if there is an alarm condition
- if (ds.hasAlarm()) {
- // Print a warning message with the current temperature
- Serial.print("Warning! Temperature is ");
- Serial.print(ds.getTempC());
- Serial.println(" C");
- }
- } else {
- Serial.println("Device not found!"); // Print error if device is not found
- }
- // Wait for 10 seconds before the next loop iteration
- delay(10000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement