Smart Home Automation Forum
[Arduino IDE demo source code for KC868-A16]--#05-DS18B20 - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A16 (https://www.kincony.com/forum/forumdisplay.php?fid=25)
+--- Thread: [Arduino IDE demo source code for KC868-A16]--#05-DS18B20 (/showthread.php?tid=1617)



[Arduino IDE demo source code for KC868-A16]--#05-DS18B20 - KinCony Support - 01-05-2022

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);
}