Smart Home Automation Forum
[Arduino demo source code for KC868-A4]-04 read DS18B20 temperature sensor - 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-A4 (https://www.kincony.com/forum/forumdisplay.php?fid=21)
+--- Thread: [Arduino demo source code for KC868-A4]-04 read DS18B20 temperature sensor (/showthread.php?tid=1643)



[Arduino demo source code for KC868-A4]-04 read DS18B20 temperature sensor - KinCony Support - 01-07-2022

Code 3: //The demo code is DS18B20    You can copy the code to your Arduino IDE

Code:
#include <DS18B20.h>

#define LOW_ALARM 20
#define HIGH_ALARM 25

DS18B20 ds(13);   //IO13

void setup() {
  Serial.begin(9600);

  while (ds.selectNext()) {
    ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  }
}

void loop() {
  ds.doConversion();

  while (ds.selectNextAlarm()) {
    Serial.print("Alarm Low: ");
    Serial.print(ds.getAlarmLow());
    Serial.println(" C");
    Serial.print("Alarm High: ");
    Serial.print(ds.getAlarmHigh());
    Serial.println(" C");
    Serial.print("Temperature: ");
    Serial.print(ds.getTempC());
    Serial.println(" C\n");
  }

  delay(1000);
}