ksszztof

arduino

Apr 2nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. // Program odczytuje temperaturę z czujnika i pipczy gdy temperatura spada ponizej 24C
  2.  
  3. #include <OneWire.h>
  4. #include <DS18B20.h>
  5.  
  6. // Numer pinu do którego podłaczasz czujnik
  7. #define ONEWIRE_PIN 2
  8. int BUZZER = 3; /// okreslamy pin dla buzzera
  9. // Adres czujnika
  10. byte address[8] = {0x28, 0xFF, 0x84, 0x92, 0x50, 0x15, 0x1, 0x4C};
  11.  
  12. OneWire onewire(ONEWIRE_PIN);
  13. DS18B20 sensors(&onewire);
  14.  
  15. void setup() {
  16. while(!Serial);
  17. Serial.begin(9600);
  18.  
  19. sensors.begin();
  20. sensors.request(address);
  21. pinMode(BUZZER, OUTPUT);
  22. }
  23.  
  24. void loop() {
  25. if (sensors.available())
  26. {
  27. float temperature = sensors.readTemperature(address); // odczyt
  28.  
  29. Serial.print(temperature); // wypis do konsoli
  30. Serial.println(F(" 'C"));
  31.  
  32. sensors.request(address);
  33. if (temperature < 24) // warunek na buzzer - poniej 24 C zacznie pipczec
  34. {digitalWrite(BUZZER, HIGH); /// bzyt
  35. delay(1000);
  36. digitalWrite(BUZZER, LOW); // wylaczenie bzyt
  37. delay(1000);
  38. }
  39. }
  40.  
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment