CCCPaste

"Temperature Alert" rev_02

/********* 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 Alert"
	- Source Code compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-06-28 19:33:05

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Read sensor and print on serial monitor */
/****** END SYSTEM REQUIREMENTS *****/


/****** DEFINITION OF LIBRARIES *****/
#include   //https://github.com/matmunk/DS18B20

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Sensor_DS18B20_DQ_PIN_D4 = 4;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
DS18B20 ds(Sensor_DS18B20_DQ_PIN_D4);  // Initialize DS18B20 object with the pin number

/****** GLOBAL VARIABLES *****/
#define LOW_ALARM 20
#define HIGH_ALARM 25
uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};  // Example address

void setup(void) {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(Sensor_DS18B20_DQ_PIN_D4, INPUT);

  if (ds.select(address)) {
    ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  } else {
    Serial.println("Device not found!");
  }
}

void loop(void) {
  // put your main code here, to run repeatedly:
  if (ds.select(address)) {
    if (ds.hasAlarm()) {
      Serial.print("Warning! Temperature is ");
      Serial.print(ds.getTempC());
      Serial.println(" C");
    } else {
      Serial.print("Temperature is ");
      Serial.print(ds.getTempC());
      Serial.println(" C");
    }
  } else {
    Serial.println("Device not found!");
  }

  delay(10000);
}

/* END CODE */