Advertisement
seston

greenhouse 25.05.2014 with moisture

May 25th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <LiquidCrystal.h>
  3. #include <DallasTemperature.h>
  4.  
  5.  
  6.  
  7.  
  8. //LCD 20x4 pins
  9. LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
  10.  
  11. // Data wire is plugged into pin 3 on the Arduino
  12. #define ONE_WIRE_BUS 3
  13. //#define contrastPin 9
  14. //#define contrast 110
  15.  
  16. // Setup a oneWire instance to communicate with any OneWire devices
  17. OneWire oneWire(ONE_WIRE_BUS);
  18.  
  19. // Pass our oneWire reference to Dallas Temperature.
  20. DallasTemperature sensors(&oneWire);
  21.  
  22. // Assign the addresses of your 1-Wire temp sensors.
  23. // See the tutorial on how to obtain these addresses:
  24. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  25.  
  26. DeviceAddress pinnaseThermometer = { 0x28, 0x0A, 0x03, 0xD9, 0x04, 0x00, 0x00, 0x93 };
  27. DeviceAddress kasvuhoonesThermometer = { 0x28, 0xF3, 0x33, 0xD8, 0x04, 0x00, 0x00, 0x7C };
  28. DeviceAddress outdoorThermometer = { 0x28, 0xB3, 0xD9, 0xD8, 0x04, 0x00, 0x00, 0x6E };
  29. DeviceAddress mullasThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
  30.  
  31.  
  32. #define moisture_input A0 // analog pin 0 nael 1
  33. #define divider_top A1 // takisti analog pin 1 10K A1-st A0-i, divider top
  34. #define divider_bottom A2 // nael 2 analog pin 2
  35. int waterPump =A5; // led, water pump analog pin 5
  36. int moisture;
  37. int Koguprotsent;
  38. int tempHigh =A3; // relee mis avab luugi
  39. int tempLow =A4; //relee mis suleb luugi
  40.  
  41. int X=0;
  42.  
  43. void setup(void)
  44. {
  45.  
  46. lcd.begin(16, 2);
  47. lcd.clear();
  48. lcd.setCursor(0,0);
  49.  
  50. pinMode (tempLow, OUTPUT);
  51. pinMode (tempHigh, OUTPUT);
  52. pinMode (waterPump, OUTPUT);
  53. digitalWrite(waterPump, HIGH);
  54. digitalWrite (tempLow, HIGH);
  55. digitalWrite (tempHigh, HIGH);
  56.  
  57.  
  58. // start serial port
  59. Serial.begin(9600);
  60.  
  61.  
  62. // Start up the library
  63. sensors.begin();
  64. // set the resolution to 10 bit (good enough?)
  65. sensors.setResolution(pinnaseThermometer, 9);
  66. sensors.setResolution(kasvuhoonesThermometer, 9);
  67. sensors.setResolution(outdoorThermometer, 9);
  68. sensors.setResolution(mullasThermometer, 9);
  69.  
  70. }
  71.  
  72. void printTemperature(DeviceAddress deviceAddress)
  73. {
  74. float tempC = sensors.getTempC(deviceAddress);
  75. if (tempC == -127.00) {
  76. Serial.print("Error getting temperature");
  77. } else {
  78. Serial.print(tempC);
  79. Serial.print("C ");
  80.  
  81. //-- panin koodi siia..
  82. }
  83.  
  84. Serial.println();
  85. if (tempC >= 27 && X ==0){
  86. digitalWrite(tempHigh, HIGH);
  87. Serial.print("Palav on liiga.Avame luugi.");
  88. delay(6000); //luugi avamise aeg mootorile
  89. digitalWrite(tempHigh, LOW);
  90. X = 1;
  91. }
  92.  
  93. if (tempC <= 24 && X ==1){
  94. Serial.print("Jahedaks kisub.Sulgeme luugi.");
  95. X = 0;
  96.  
  97. digitalWrite(tempLow, HIGH);
  98. delay(6000); // luugi sulgemise aeg mootorile
  99. digitalWrite(tempLow, LOW);
  100.  
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. }
  111.  
  112. void loop(void)
  113. {
  114. //---- soil
  115. // digitalWrite(waterPump, HIGH);
  116.  
  117. // Serial.print("Getting Soil Moisture...\n\r");
  118. moisture=SoilMoisture(); // soilmoister as variable
  119. Koguprotsent = ((moisture*100)/900); // mina sain max väärtuseks 950
  120. Serial.print("Niiskuse absoluut arv: ");
  121. Serial.println(moisture);
  122. delay(2000);
  123.  
  124. Serial.print("Mullas on niiskust ");
  125. Serial.print(Koguprotsent);
  126. Serial.print(" % ");
  127.  
  128. Serial.println();
  129.  
  130.  
  131. delay(2000); // tuleks sättida endale sobivaks.
  132.  
  133.  
  134.  
  135. if (Koguprotsent >= 38){
  136. Serial.print("Pinnas on niiske parajalt.");
  137. delay(1000);
  138.  
  139. Serial.println();
  140.  
  141. // digitalWrite(waterPump, HIGH);
  142.  
  143. }
  144. if (Koguprotsent <= 37){
  145. Serial.print("Peab kastma.Appi-appi!!!Kuivame!");
  146.  
  147. digitalWrite(waterPump, LOW);
  148. delay(1000); //pumba töö aeg.Katsetamise käigus selgub palju oleks normaalne aeg pumba tööks,et ei tekiks uputust.
  149. digitalWrite(waterPump, HIGH);
  150.  
  151. Serial.println();
  152. }
  153.  
  154. //---------- temp
  155. delay(1000);
  156. Serial.print("Getting temperatures...\n\r");
  157. sensors.requestTemperatures();
  158. delay(2000);
  159. Serial.print("Mulla temperature is: ");
  160. printTemperature(pinnaseThermometer);
  161. Serial.print("\n\r");
  162. delay(1000);
  163. Serial.print("Kasvuhoones temperature is: ");
  164. printTemperature(kasvuhoonesThermometer);
  165. Serial.print("\n\r");
  166. delay(1000);
  167. Serial.print("Outdoor temperature is: ");
  168. printTemperature(outdoorThermometer);
  169. Serial.print("\n\r");
  170. delay(1000);
  171. Serial.print("Mullas temperature is: ");
  172. printTemperature(mullasThermometer);
  173. Serial.print("\n\r");
  174. delay(1000);
  175. }
  176.  
  177.  
  178.  
  179.  
  180. int SoilMoisture(){
  181. int reading;
  182. // set driver pins to outputs
  183. pinMode(divider_top,OUTPUT);
  184. pinMode(divider_bottom,OUTPUT);
  185.  
  186. // drive a current through the divider in one direction
  187. digitalWrite(divider_top,LOW);
  188. digitalWrite(divider_bottom,HIGH);
  189.  
  190. // wait a moment for capacitance effects to settle
  191. delay(1000);
  192.  
  193. // take a reading
  194. reading=analogRead(moisture_input);
  195.  
  196. // reverse the current
  197. digitalWrite(divider_top,HIGH);
  198. digitalWrite(divider_bottom,LOW);
  199.  
  200. // give as much time in 'reverse' as in 'forward'
  201. delay(1000);
  202.  
  203. // stop the current
  204. digitalWrite(divider_bottom,LOW);
  205.  
  206. return reading;
  207.  
  208. //relays for temp
  209. pinMode(tempHigh,OUTPUT);
  210.  
  211.  
  212.  
  213.  
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement