Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino IDE demo source code for KC868-A8]--#04-DS18B20
#1
Star 
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!");
  }
}
       
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)