01-05-2022, 06:49 AM
(This post was last modified: 01-05-2022, 07:36 AM by KinCony Support.)
Code 3: //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
//IO14 or IO13 or IO32 or IO33 Choose one of the IO port
DS18B20 ds(14); //DS18B20 -01
//DS18B20 ds(13); //DS18B20 -02
//DS18B20 ds(32); //DS18B20 -03
//DS18B20 ds(33); //DS18B20 -04
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!");
}
}