Advertisement
seston

ds3231 kasvuhoone luugid 1

Apr 14th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <LiquidCrystal.h>
  3. #include <DallasTemperature.h>
  4. #include <Wire.h>
  5. #include "Sodaq_DS3231.h"
  6.  
  7. char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. //LCD 20x4 pins
  15. LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
  16.  
  17. // Data wire is plugged into pin 3 on the Arduino
  18. #define ONE_WIRE_BUS 3
  19. //#define contrastPin 9
  20. //#define contrast 110
  21.  
  22. // Setup a oneWire instance to communicate with any OneWire devices
  23. OneWire oneWire(ONE_WIRE_BUS);
  24.  
  25. // Pass our oneWire reference to Dallas Temperature.
  26. DallasTemperature sensors(&oneWire);
  27.  
  28. // Assign the addresses of your 1-Wire temp sensors.
  29. // See the tutorial on how to obtain these addresses:
  30. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  31.  
  32. DeviceAddress pinnaseThermometer = { 0x28, 0x0A, 0x03, 0xD9, 0x04, 0x00, 0x00, 0x93 };
  33. DeviceAddress kasvuhoonesThermometer = { 0x28, 0xF3, 0x33, 0xD8, 0x04, 0x00, 0x00, 0x7C };
  34. DeviceAddress outdoorThermometer = { 0x28, 0xB3, 0xD9, 0xD8, 0x04, 0x00, 0x00, 0x6E };
  35. DeviceAddress mullasThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
  36.  
  37.  
  38.  
  39. int tempHigh1 =53; // relee 1 mis avab luugi
  40. int tempLow1 =51; //relee 2 mis suleb luugi
  41. int tempHigh2 =49; // relee 3 mis avab luugi
  42. int tempLow2 =47; //relee 4 mis suleb luugi
  43. int tempHigh3 =45; // relee 5 mis avab luugi
  44. int tempLow3 =43; //relee 6 mis suleb luugi
  45.  
  46. int X=0;
  47.  
  48. void setup(void)
  49. {
  50.  
  51. Serial.begin(57600);
  52. Wire.begin();
  53. rtc.begin();
  54. lcd.begin(20, 4);
  55. lcd.clear();
  56. //lcd.setCursor(0,0);
  57.  
  58. pinMode (tempLow1, OUTPUT);
  59. pinMode (tempHigh1, OUTPUT);
  60. pinMode (tempLow2, OUTPUT);
  61. pinMode (tempHigh2, OUTPUT);
  62. pinMode (tempLow3, OUTPUT);
  63. pinMode (tempHigh3, OUTPUT);
  64.  
  65. digitalWrite (tempLow1, HIGH);
  66. digitalWrite (tempHigh1, HIGH);
  67. digitalWrite (tempLow2, HIGH);
  68. digitalWrite (tempHigh2, HIGH);
  69. digitalWrite (tempLow3, HIGH);
  70. digitalWrite (tempHigh3, HIGH);
  71.  
  72.  
  73. // start serial port
  74. //Serial.begin(9600);
  75.  
  76.  
  77. // Start up the library
  78. sensors.begin();
  79. // set the resolution to 10 bit (good enough?)
  80. sensors.setResolution(pinnaseThermometer, 9);
  81. sensors.setResolution(kasvuhoonesThermometer, 9);
  82. sensors.setResolution(outdoorThermometer, 9);
  83. sensors.setResolution(mullasThermometer, 9);
  84.  
  85. }
  86.  
  87. void printTemperature(DeviceAddress deviceAddress)
  88. {
  89. float tempC = sensors.getTempC(deviceAddress);
  90. if (tempC == -127.00) {
  91. Serial.print("Error getting temperature");
  92. } else {
  93. Serial.print(tempC);
  94. Serial.print("C ");
  95.  
  96. //-- panin koodi siia..
  97. }
  98.  
  99. Serial.println();
  100. if (tempC >= 27 && X ==0){
  101. digitalWrite(tempHigh1, HIGH);
  102. Serial.print("Palav on liiga.Avame luugi.");
  103. delay(6000); //luugi avamise aeg mootorile
  104. digitalWrite(tempHigh1, LOW);
  105. X = 1;
  106. }
  107.  
  108. if (tempC <= 24 && X ==1){
  109. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  110. X = 0;
  111.  
  112. digitalWrite(tempLow1, HIGH);
  113. delay(6000); // luugi sulgemise aeg mootorile
  114. digitalWrite(tempLow1, LOW);
  115.  
  116.  
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. }
  126.  
  127. void loop(void)
  128. {
  129.  
  130.  
  131. //---------- temp
  132. delay(1000);
  133. Serial.print("Getting temperatures...\n\r");
  134. sensors.requestTemperatures();
  135. delay(2000);
  136. Serial.print("Mulla temperature is: ");
  137. printTemperature(pinnaseThermometer);
  138. Serial.print("\n\r");
  139. delay(1000);
  140. Serial.print("Kasvuhoones temperature is: ");
  141. printTemperature(kasvuhoonesThermometer);
  142. Serial.print("\n\r");
  143. delay(1000);
  144. Serial.print("Outdoor temperature is: ");
  145. printTemperature(outdoorThermometer);
  146. Serial.print("\n\r");
  147. delay(1000);
  148. Serial.print("Mullas temperature is: ");
  149. printTemperature(mullasThermometer);
  150. Serial.print("\n\r");
  151. delay(1000);
  152. {
  153. DateTime now = rtc.now(); //get the current date-time
  154. uint32_t ts = now.getEpoch();
  155.  
  156. if (old_ts == 0 || old_ts != ts)
  157. old_ts = ts;
  158. Serial.print(now.year(), DEC);
  159. Serial.print('/');
  160. Serial.print(now.month(), DEC);
  161. Serial.print('/');
  162. Serial.print(now.date(), DEC);
  163. Serial.print(' ');
  164. Serial.print(now.hour(), DEC);
  165. Serial.print(':');
  166. Serial.print(now.minute(), DEC);
  167. Serial.print(':');
  168. Serial.print(now.second(), DEC);
  169. Serial.print(' ');
  170. Serial.print(weekDay[now.dayOfWeek()]);
  171. Serial.println();
  172. Serial.print("Seconds since Unix Epoch: ");
  173. Serial.print(ts, DEC);
  174. Serial.println();
  175.  
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement