Advertisement
seston

ds3231 kasvuhoone luugid 2

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