01-05-2022, 08:04 AM
Code4: //The demo code is DS18B20 You can copy the code to your Arduino IDE
Code:
#include <DS18B20.h>
#define LOW_ALARM 10
#define HIGH_ALARM 15
DS18B20 ds(33); //PIN #33
uint8_t address[] = {40, 168, 111, 11, 44, 32, 1, 185};
uint8_t selected;
void setup() {
Serial.begin(9600);
selected = ds.select(address);
if (selected) {
ds.setAlarms(LOW_ALARM, HIGH_ALARM);
} else {
Serial.println("Device not found!");
}
}
void loop() {
if (selected) {
if (ds.hasAlarm()) {
Serial.print("Warning! Temperature is ");
Serial.print(ds.getTempC());
Serial.println(" C");
}
} else {
Serial.println("Device not found!");
}
//delay(10000);
}