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 Monitor"
- - Source Code compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-03-25 02:46:26
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* // ### LOAD REQUIRED ARDUINO LIBRARIES ### */
- /* #include <OneWire.h> // Library by Jim Studt */
- /* etc. #include <DallasTemperature.h> // Library */
- /* by Miles Burton etc. // ### INITIALISE ### */
- /* // ## INITIALISE ONE WIRE BU ## // Define pin D5 */
- /* of the Ardui */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <OneWire.h> // Library by Jim Studt
- #include <DallasTemperature.h> // Library by Miles Burton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t temp_DS18B20_DQ_PIN_D5 = 5; // Change the pin to D5
- /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
- OneWire oneWire(temp_DS18B20_DQ_PIN_D5); // Initialize the OneWire object
- DallasTemperature sensors(&oneWire); // Initialize the DallasTemperature object
- /****** DEFINITION OF TEMPERATURE ALARM THRESHOLDS *****/
- const int LOW_ALARM = 20; // Set the low temperature alarm threshold
- const int HIGH_ALARM = 25; // Set the high temperature alarm threshold
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600); // Initialize Serial communication
- sensors.begin(); // Initialize the DallasTemperature library
- // Get the address of the sensor
- DeviceAddress address;
- sensors.getAddress(address, 0);
- // Set the high and low temperature alarms
- sensors.setHighAlarmTemp(address, HIGH_ALARM);
- sensors.setLowAlarmTemp(address, LOW_ALARM);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- sensors.requestTemperatures(); // Send the command to read temperatures
- float temperatureC = sensors.getTempCByIndex(0); // Read the temperature in Celsius
- if (sensors.hasAlarm())
- {
- Serial.print("Warning! Temperature is ");
- Serial.print(temperatureC);
- Serial.println(" C");
- }
- delay(10000); // Wait for 10 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement