Advertisement
seston

soojendus ja kastmine keldri

Mar 18th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <LiquidCrystal.h>
  4. /*
  5. 0 - 232 rxd
  6. 1 - 232 txd
  7. 2 - enable (LCD)
  8. 3 - temp sensor (LCD)
  9. 4 - sd card 9 (ETHERNET SHIELD)
  10. 5 - lcd d4 (LCD)
  11. 6 - lcd d5 (LCD)
  12. 7 - lcd d6 (LCD)
  13. 8 - lcd d7 (LCD)
  14. 9
  15. 10 - w5100 select(ETHERNET SHIELD)
  16. 11 - SPI MOSI (ETHERNET SHIELD)
  17. 12 - SPI MISO (ETHERNET SHIELD)
  18. 13 - SPI CLK (ETHERNET SHIELD)
  19.  
  20. ANALOG
  21. 0 - MOISTURE in (analog)
  22. 1 - moisture (digital)
  23. 2 - moister 1 (digital)
  24. 3 - window open (digital)
  25. 4 - window close (digital)
  26. 5 - water pump (digital)
  27. */
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. // initialize the library with the numbers of the interface pins
  36. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  37.  
  38. // Data wire is plugged into pin 3 on the Arduino
  39. #define ONE_WIRE_BUS 9
  40.  
  41. // Setup a oneWire instance to communicate with any OneWire devices
  42. OneWire oneWire(ONE_WIRE_BUS);
  43.  
  44. // Pass our oneWire reference to Dallas Temperature.
  45. DallasTemperature sensors(&oneWire);
  46.  
  47. // Assign the addresses of your 1-Wire temp sensors.
  48. // See the tutorial on how to obtain these addresses:
  49. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  50.  
  51. DeviceAddress insideThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
  52. //DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
  53. //DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };
  54.  
  55. #define moisture_input 0 // analog pin 0
  56. #define divider_top A1 // takisti digital pin 9
  57. #define divider_bottom A2 // nael 1 digital pin 10
  58. int waterPump =7; // led, water pump digital pin 7
  59. int waterLed = 8; //led kui niiskust on 450
  60. int moisture;
  61. double Koguprotsent;
  62. int tempHigh =6; // relee mis avab luugi
  63. int tempLow =5; //relee mis suleb luugi
  64. int led = 13; //led pin kütte releele
  65.  
  66. int X=0;
  67.  
  68. void setup(void)
  69. {
  70.  
  71. pinMode (tempLow, OUTPUT);
  72. pinMode (tempHigh, OUTPUT);
  73. pinMode (waterPump, OUTPUT);
  74. pinMode (led, OUTPUT);
  75. pinMode (waterLed, OUTPUT);
  76. digitalWrite(waterPump, LOW);
  77. digitalWrite(waterLed, HIGH);
  78. digitalWrite (tempLow, LOW);
  79. digitalWrite (tempHigh, HIGH);
  80. digitalWrite (led, HIGH);
  81. // start serial port
  82. Serial.begin(9600);
  83. // Start up the library
  84. sensors.begin();
  85. // set the resolution to 10 bit (good enough?)
  86. sensors.setResolution(insideThermometer, 10);
  87. // sensors.setResolution(outsideThermometer, 10);
  88. // sensors.setResolution(dogHouseThermometer, 10);
  89. }
  90.  
  91. void printTemperature(DeviceAddress deviceAddress)
  92. {
  93. float tempC = sensors.getTempC(deviceAddress);
  94. if (tempC == -127.00) {
  95. Serial.print("Error getting temperature");
  96. } else {
  97. Serial.print("C: ");
  98. Serial.print(tempC);
  99. //-- panin koodi siia..
  100. }
  101.  
  102. if (tempC >= 24 && X ==0){
  103. digitalWrite(tempHigh, LOW);
  104. Serial.print("Stop heating.");
  105. digitalWrite(led, LOW);
  106. //delay(6000);
  107. //digitalWrite(tempHigh, LOW);
  108. X = 1;
  109. }
  110.  
  111. if (tempC <= 24 && X ==1){
  112. Serial.print("Heating start");
  113. X = 0;
  114.  
  115. digitalWrite(tempHigh, HIGH);
  116. digitalWrite(led, HIGH);
  117. //delay(6000);
  118. //digitalWrite(tempLow, LOW);
  119. }
  120.  
  121.  
  122.  
  123.  
  124. // Serial.print(" F: ");
  125. // Serial.print(DallasTemperature::toFahrenheit(tempC));
  126.  
  127. }
  128.  
  129. void loop(void)
  130. {
  131.  
  132. //---- soil
  133.  
  134. // Serial.print("Getting Soil Moisture...\n\r");
  135. moisture=SoilMoisture(); // soilmoister as variable
  136. Koguprotsent = ((moisture*100)/950.0); // mina sain max väärtuseks 950
  137. Serial.print("Niiskuse absoluut arv: ");
  138. Serial.println(moisture);
  139.  
  140. Serial.print("Mullas on niiskust ");
  141. Serial.print(Koguprotsent);
  142. Serial.print(" % ");
  143.  
  144. Serial.println();
  145.  
  146.  
  147. delay(1000); // tuleks sättida endale sobivaks.
  148.  
  149.  
  150.  
  151. if (moisture >= 650){
  152.  
  153. digitalWrite(waterPump, LOW);
  154. Serial.print(" Water pump off");
  155. digitalWrite(waterLed, LOW);
  156.  
  157. }
  158. if (moisture <= 600){
  159.  
  160. digitalWrite(waterPump, HIGH);
  161. Serial.print("Water pump High");
  162. digitalWrite(waterLed, HIGH);
  163. delay(1000); //pumba töö aeg.Katsetamise käigus selgub palju oleks normaalne aeg pumba tööks,et ei tekiks uputust.
  164. digitalWrite(waterPump, LOW);
  165.  
  166.  
  167. }
  168.  
  169. //---------- temp
  170. delay(1000);
  171. Serial.print("Getting temperatures...\n\r");
  172. sensors.requestTemperatures();
  173.  
  174. Serial.print("Inside temperature is: ");
  175. printTemperature(insideThermometer);
  176. Serial.print("\n\r");
  177. // Serial.print("Outside temperature is: ");
  178. // printTemperature(outsideThermometer);
  179. // Serial.print("\n\r");
  180. // Serial.print("Dog House temperature is: ");
  181. // printTemperature(dogHouseThermometer);
  182. // Serial.print("\n\r\n\r");
  183. }
  184.  
  185.  
  186.  
  187.  
  188. int SoilMoisture(){
  189. int reading;
  190. // set driver pins to outputs
  191. pinMode(divider_top,OUTPUT);
  192. pinMode(divider_bottom,OUTPUT);
  193.  
  194. // drive a current through the divider in one direction
  195. digitalWrite(divider_top,LOW);
  196. digitalWrite(divider_bottom,HIGH);
  197.  
  198. // wait a moment for capacitance effects to settle
  199. delay(1000);
  200.  
  201. // take a reading
  202. reading=analogRead(moisture_input);
  203.  
  204. // reverse the current
  205. digitalWrite(divider_top,HIGH);
  206. digitalWrite(divider_bottom,LOW);
  207.  
  208. // give as much time in 'reverse' as in 'forward'
  209. delay(1000);
  210.  
  211. // stop the current
  212. digitalWrite(divider_bottom,LOW);
  213.  
  214. return reading;
  215.  
  216. //relays for temp
  217. pinMode(tempHigh,OUTPUT);
  218.  
  219.  
  220.  
  221.  
  222.  
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement