Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DS18B20.h>
  3. #include <LiquidCrystal.h>
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6. LiquidCrystal_I2C lcd(0x27, 20, 4);
  7. #define ONE_WIRE_BUS 11
  8. OneWire oneWire(ONE_WIRE_BUS);
  9. DS18B20 sensors(&oneWire);
  10. #define SENSORS_NUM 2
  11. const int tempplus = 6;
  12. const int tempminus = 7;
  13. const int wlacznik = 5;
  14. float tempz = 56;
  15. float temperature;
  16. float temperatura;
  17. byte addres[8] = {0x28, 0x8C, 0x4D, 0x1F, 0x7, 0x0, 0x0, 0x54};
  18. byte address [8] = {0x28, 0x61, 0x73, 0x1F, 0x7, 0x0, 0x0, 0x11};
  19. int BeepPin = 13; //numer pinu buzzera
  20. int poprzedniStan = LOW;
  21. boolean stan = 0;
  22.  
  23. void praca()
  24. {
  25.  
  26. lcd.setCursor(0, 0);
  27. lcd.print("T.Pieca ~");
  28. lcd.setCursor(0, 1);
  29. lcd.print("T.Boilera ~");
  30. lcd.setCursor(0, 2);
  31. lcd.print("Stan pompy ~");
  32. lcd.setCursor(0, 3);
  33. lcd.print("Start pompy ~");
  34. lcd.setCursor(14, 3);
  35. lcd.print(tempz, 1);
  36.  
  37. if (sensors.available())
  38. {
  39. temperature = sensors.readTemperature(addres);
  40. lcd.setCursor(14, 0);
  41. lcd.print(temperature, 1);
  42. temperatura = sensors.readTemperature(address);
  43. lcd.setCursor(14, 1);
  44. lcd.print(temperatura, 1);
  45. sensors.request();
  46.  
  47. }
  48.  
  49. if (temperature >= tempz) {
  50. digitalWrite(10, HIGH);
  51. lcd.setCursor(14, 2);
  52. lcd.print("PRACA");
  53. if (poprzedniStan != digitalRead(10)) {
  54. poprzedniStan = digitalRead(10);
  55. Ton();
  56. }
  57. }
  58. if (temperature <= tempz - 5) {
  59. digitalWrite(10, LOW);
  60. lcd.setCursor(14, 2);
  61. lcd.print("STOP ");
  62. if (poprzedniStan != digitalRead(10)) {
  63. poprzedniStan = digitalRead(10);
  64. Beep();
  65. }
  66. }
  67. }
  68. void manual()
  69. {
  70.  
  71. lcd.setCursor(4, 0);
  72. lcd.print("temp.");
  73. lcd.setCursor(10, 0);
  74. lcd.print(temperature, 1);
  75. lcd.setCursor(1, 2);
  76. lcd.print("< POMPA PRACUJE >");
  77. }
  78.  
  79. void Ton()
  80. { int i = 0;
  81. while (i < 4)
  82. {
  83. digitalWrite(BeepPin, HIGH);
  84. delay(80);
  85. digitalWrite(BeepPin, LOW);
  86. delay(40);
  87. i++;
  88. }
  89. }
  90.  
  91. void Beep()
  92. {
  93. digitalWrite(BeepPin, HIGH); //stan wysoki żeby odpalić buzzer
  94. delay(800);
  95. digitalWrite(BeepPin, LOW); //stan niski - kończymy piskanie
  96. }
  97.  
  98. void Pip()
  99. { int i = 0;
  100. while (i < 4)
  101. {
  102. digitalWrite(BeepPin, HIGH);
  103. delay(80);
  104. digitalWrite(BeepPin, LOW);
  105. delay(50);
  106. i++;
  107. }
  108. }
  109. void setup()
  110. {
  111. sensors.begin(12); //rozpoczęcie pracy DS18B20
  112. sensors.request();
  113. pinMode(wlacznik, INPUT_PULLUP);
  114. pinMode(tempplus, INPUT_PULLUP);
  115. pinMode(tempminus, INPUT_PULLUP);
  116. pinMode(10, OUTPUT);
  117. pinMode(12, OUTPUT);
  118. pinMode(BeepPin, OUTPUT); //ustawiamy
  119. digitalWrite(BeepPin, LOW); //tak dla pewności żeby wyzerować
  120. lcd.init();
  121. lcd.backlight();
  122. lcd.clear();
  123.  
  124. }
  125.  
  126.  
  127. void loop()
  128. {
  129.  
  130. if (digitalRead(tempplus) == LOW) {
  131. tempz++;
  132. }
  133.  
  134. if (digitalRead(tempminus) == LOW) {
  135. tempz--;
  136. }
  137.  
  138.  
  139. if (digitalRead(wlacznik) == LOW)
  140. {
  141. delay(20);
  142. stan = !stan;
  143. digitalWrite(12, stan);
  144. while (digitalRead(wlacznik) == LOW);
  145. delay(20);
  146. Pip();
  147. lcd.clear();
  148. }
  149. if (stan == 0)
  150. {
  151. praca();
  152. }
  153. else
  154. {
  155. manual();
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement