Single.ino 591 B

123456789101112131415161718192021222324252627282930313233
  1. #include <DS18B20.h>
  2. #define LOW_ALARM 20
  3. #define HIGH_ALARM 25
  4. DS18B20 ds(2);
  5. uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
  6. uint8_t selected;
  7. void setup() {
  8. Serial.begin(9600);
  9. selected = ds.select(address);
  10. if (selected) {
  11. ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  12. } else {
  13. Serial.println("Device not found!");
  14. }
  15. }
  16. void loop() {
  17. if (selected) {
  18. if (ds.hasAlarm()) {
  19. Serial.print("Warning! Temperature is ");
  20. Serial.print(ds.getTempC());
  21. Serial.println(" C");
  22. }
  23. } else {
  24. Serial.println("Device not found!");
  25. }
  26. delay(10000);
  27. }