Advertisement
seston

kasvuhoone 3 luuki + ds3231 + lcd 20x4 poolik 1

Apr 20th, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 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 1.1 mis suleb luugi
  42. int tempHigh2 =49; // relee 2 mis avab luugi
  43. int tempLow2 =47; //relee 2.2 mis suleb luugi
  44. int tempHigh3 =45; // relee 3 mis avab luugi
  45. int tempLow3 =43; //relee 3.3 mis suleb luugi
  46.  
  47. int X=0;
  48. int X1=0;
  49. int X2=0;
  50.  
  51. void setup(void)
  52. {
  53.  
  54. Serial.begin(57600);
  55. Wire.begin();
  56. rtc.begin();
  57. lcd.begin(20, 4);
  58. lcd.clear();
  59. lcd.setCursor(0,0);
  60.  
  61. pinMode (tempLow1, OUTPUT);
  62. pinMode (tempHigh1, OUTPUT);
  63. pinMode (tempLow2, OUTPUT);
  64. pinMode (tempHigh2, OUTPUT);
  65. pinMode (tempLow3, OUTPUT);
  66. pinMode (tempHigh3, OUTPUT);
  67.  
  68. digitalWrite (tempLow1, HIGH);
  69. digitalWrite (tempHigh1, HIGH);
  70. digitalWrite (tempLow2, HIGH);
  71. digitalWrite (tempHigh2, HIGH);
  72. digitalWrite (tempLow3, HIGH);
  73. digitalWrite (tempHigh3, HIGH);
  74.  
  75.  
  76. // start serial port
  77. //Serial.begin(9600);
  78.  
  79.  
  80. // Start up the library
  81. sensors.begin();
  82. // set the resolution to 10 bit (good enough?)
  83. sensors.setResolution(pinnaseThermometer, 9); //soil ds18b20
  84. sensors.setResolution(kasvuhoonesThermometer, 9); //inside greenhouse ds18b20
  85. sensors.setResolution(outdoorThermometer, 9); //outdoor ds18b20
  86. //sensors.setResolution(mullasThermometer, 9); //free, not used ds18b20
  87.  
  88. }
  89.  
  90. void printTemperature(DeviceAddress deviceAddress)
  91. {
  92. float tempC = sensors.getTempC(kasvuhoonesThermometer); //temp from inside greenhouse
  93. if (tempC == -127.00) {
  94. Serial.print("Error getting temperature");
  95. } else {
  96. Serial.print(tempC);
  97. Serial.print("C ");
  98.  
  99.  
  100. lcd.print ("IN ");
  101. lcd.print(tempC);
  102.  
  103. //-- panin koodi siia.. Here for open , close windows
  104. }
  105. // luuk 1 poollahti, window 1 half open
  106.  
  107.  
  108. Serial.println();
  109. if (tempC >= 19 && X ==0){
  110. digitalWrite(tempHigh1, HIGH);
  111. Serial.print("Window 1 half opening."); //
  112. delay(6000); //time for half opening window 1
  113. digitalWrite(tempHigh1, LOW);
  114. X = 1;
  115. }
  116.  
  117. if (tempC <= 18 && X ==1){
  118. Serial.print("T. is low. Half opened window 1 close");
  119. X = 0;
  120.  
  121. digitalWrite(tempLow1, HIGH);
  122. delay(6000); // time for close half opened window 1
  123. digitalWrite(tempLow1, LOW);
  124. }
  125.  
  126. //luuk 1 täitsa lahti, for window 1 full opening
  127.  
  128. Serial.println();
  129. if (tempC >= 21 && X ==0){
  130. digitalWrite(tempHigh1, HIGH);
  131. Serial.print("Window 1 full opening.");
  132. delay(6000); //luugi avamise aeg mootorile, time for window 1 full opening, from position half opened.
  133. digitalWrite(tempHigh1, LOW);
  134. X = 1;
  135. }
  136.  
  137. if (tempC <= 20 && X ==1){
  138. Serial.print("Full opened window to position half opened");
  139. X = 0;
  140.  
  141. digitalWrite(tempLow1, HIGH);
  142. delay(6000); // luugi sulgemise aeg mootorile, time for half opened window to position closed
  143. digitalWrite(tempLow1, LOW);
  144. }
  145.  
  146. //luuk 2
  147.  
  148.  
  149. Serial.println();
  150. if (tempC >= 23 && X ==0){
  151. digitalWrite(tempHigh2, HIGH);
  152. Serial.print("Palav on liiga.Avame luugi.");
  153. delay(6000); //luugi avamise aeg mootorile
  154. digitalWrite(tempHigh2, LOW);
  155. X = 1;
  156. }
  157.  
  158. if (tempC <= 22 && X ==1){
  159. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  160. X = 0;
  161.  
  162. digitalWrite(tempLow2, HIGH);
  163. delay(6000); // luugi sulgemise aeg mootorile
  164. digitalWrite(tempLow2, LOW);
  165. }
  166.  
  167. //luuk 2 täitsa lahti
  168. Serial.println();
  169. if (tempC >= 25 && X ==0){
  170. digitalWrite(tempHigh2, HIGH);
  171. Serial.print("Palav on liiga.Avame luugi.");
  172. delay(6000); //luugi avamise aeg mootorile
  173. digitalWrite(tempHigh2, LOW);
  174. X = 1;
  175. }
  176.  
  177. if (tempC <= 24 && X ==1){
  178. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  179. X = 0;
  180.  
  181. digitalWrite(tempLow1, HIGH);
  182. delay(6000); // luugi sulgemise aeg mootorile
  183. digitalWrite(tempLow1, LOW);
  184. }
  185.  
  186. // luuk 3
  187.  
  188. Serial.println();
  189. if (tempC >= 27 && X ==0){
  190. digitalWrite(tempHigh3, HIGH);
  191. Serial.print("Palav on liiga.Avame luugi.");
  192. delay(6000); //luugi avamise aeg mootorile
  193. digitalWrite(tempHigh3, LOW);
  194. X = 1;
  195. }
  196.  
  197. if (tempC <= 26 && X ==1){
  198. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  199. X = 0;
  200.  
  201. digitalWrite(tempLow3, HIGH);
  202. delay(6000); // luugi sulgemise aeg mootorile
  203. digitalWrite(tempLow3, LOW);
  204. }
  205.  
  206. //luuk 3 täitsa lahti
  207.  
  208. Serial.println();
  209. if (tempC >= 29 && X ==0){
  210. digitalWrite(tempHigh3, HIGH);
  211. Serial.print("Palav on liiga.Avame luugi.");
  212. delay(6000); //luugi avamise aeg mootorile
  213. digitalWrite(tempHigh3, LOW);
  214. X = 1;
  215. }
  216.  
  217. if (tempC <= 28 && X ==1){
  218. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  219. X = 0;
  220.  
  221. digitalWrite(tempLow3, HIGH);
  222. delay(6000); // luugi sulgemise aeg mootorile
  223. digitalWrite(tempLow3, LOW);
  224. }
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. }
  233.  
  234. void loop(void)
  235. {
  236.  
  237.  
  238. //---------- temp
  239. //delay(1000);
  240. Serial.print("Getting temperatures...\n\r");
  241. sensors.requestTemperatures();
  242. //delay(1000);
  243. Serial.print("Soil: ");
  244. printTemperature(pinnaseThermometer);
  245. Serial.print("\n\r");
  246. //delay(1000);
  247. Serial.print("In: ");
  248. printTemperature(kasvuhoonesThermometer);
  249. Serial.print("\n\r");
  250. //delay(1000);
  251. Serial.print("Out: ");
  252. printTemperature(outdoorThermometer);
  253. Serial.print("\n\r");
  254. //delay(1000);
  255. //Serial.print("Mullas temperature is: ");
  256. //printTemperature(mullasThermometer);
  257. //Serial.print("\n\r");
  258. //delay(1000);
  259.  
  260. //{
  261. DateTime now = rtc.now(); //get the current date-time
  262. uint32_t ts = now.getEpoch();
  263.  
  264. if (old_ts == 0 || old_ts != ts)
  265. old_ts = ts;
  266. Serial.print(now.year(), DEC);
  267. Serial.print('/');
  268. Serial.print(now.month(), DEC);
  269. Serial.print('/');
  270. Serial.print(now.date(), DEC);
  271. Serial.print(' ');
  272. Serial.print(now.hour(), DEC);
  273. Serial.print(':');
  274. Serial.print(now.minute(), DEC);
  275. Serial.print(':');
  276. Serial.print(now.second(), DEC);
  277. Serial.print(' ');
  278. Serial.print(weekDay[now.dayOfWeek()]);
  279. Serial.println();
  280. Serial.print("Seconds since Unix Epoch: ");
  281. Serial.print(ts, DEC);
  282. Serial.println();
  283.  
  284.  
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement