Advertisement
insippo

greenhouse_insippo_main

Feb 23rd, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. //relay and moisture sensor
  4. //http://robocraft.ru/blog/arduino/444.html in russian
  5. //temperature from DS18B20
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. // Data wire is plugged into pin 3 on the Arduino
  13. #define ONE_WIRE_BUS 3
  14.  
  15. // Setup a oneWire instance to communicate with any OneWire devices
  16. OneWire oneWire(ONE_WIRE_BUS);
  17.  
  18. // Pass our oneWire reference to Dallas Temperature.
  19. DallasTemperature sensors(&oneWire);
  20.  
  21. // Assign the addresses of your 1-Wire temp sensors.
  22. // See the tutorial on how to obtain these addresses:
  23. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  24.  
  25. DeviceAddress insideThermometer = { 0x28, 0x2B, 0xE6, 0xDA, 0x02, 0x00, 0x00, 0x43 };
  26. //DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
  27. //DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };
  28.  
  29. #define moisture_input 0 // analog pin 0
  30. #define divider_top 9 // moisture resistor digital pin 9
  31. #define divider_bottom 10 // moisture sensor 1 digital pin 10
  32. int waterPump =7; // led, water pump digital pin 7
  33. int moisture;
  34. int Koguprotsent; //moisture % in Estonian
  35. int tempHigh =6; // relay who open window
  36. int tempLow =5; //relay who close window
  37.  
  38. int X=0;
  39.  
  40. void setup(void)
  41. {
  42.  
  43. pinMode (tempLow, OUTPUT);
  44. pinMode (tempHigh, OUTPUT);
  45. pinMode (waterPump, OUTPUT);
  46. digitalWrite(waterPump, LOW);
  47. digitalWrite (tempLow, LOW);
  48. digitalWrite (tempHigh, LOW);
  49. // start serial port
  50. Serial.begin(9600);
  51. // Start up the library
  52. sensors.begin();
  53. // set the resolution to 10 bit (good enough?)
  54. sensors.setResolution(insideThermometer, 10);
  55. // sensors.setResolution(outsideThermometer, 10);
  56. // sensors.setResolution(dogHouseThermometer, 10);
  57. }
  58.  
  59. void printTemperature(DeviceAddress deviceAddress)
  60. {
  61. float tempC = sensors.getTempC(deviceAddress);
  62. if (tempC == -127.00) {
  63. Serial.print("Error getting temperature");
  64. } else {
  65. Serial.print("C: ");
  66. Serial.print(tempC);
  67. //-- panin koodi siia..,comment in estonian means nothing, only for me
  68. }
  69.  
  70. if (tempC >= 27 && X ==0){ // if temp => 27 window opened
  71. digitalWrite(tempHigh, HIGH);
  72. delay(6000);
  73. digitalWrite(tempHigh, LOW);
  74. X = 1;
  75. }
  76.  
  77. if (tempC <= 24 && X ==1){ // if temp <= 24 window close
  78.  
  79. X = 0;
  80.  
  81. digitalWrite(tempLow, HIGH);
  82. delay(6000);
  83. digitalWrite(tempLow, LOW);
  84. }
  85.  
  86.  
  87.  
  88.  
  89. // Serial.print(" F: ");
  90. // Serial.print(DallasTemperature::toFahrenheit(tempC));
  91.  
  92. }
  93.  
  94. void loop(void)
  95. {
  96. //---- soil
  97.  
  98. // Serial.print("Getting Soil Moisture...\n\r");
  99. moisture=SoilMoisture(); // soilmoister as variable
  100. Koguprotsent = ((moisture*100)/970); // my moisture max value sensors in water was 950
  101. Serial.print("Sensors moisture value: ");
  102. Serial.println(moisture);
  103.  
  104. Serial.print("Moisture is ");
  105. Serial.print(Koguprotsent);
  106. Serial.print(" % ");
  107.  
  108. Serial.println();
  109.  
  110.  
  111. delay(1000); // pause 1 sec.
  112.  
  113.  
  114.  
  115. if (Koguprotsent >= 90){ //if moisture is 90 % water pump off
  116.  
  117. digitalWrite(waterPump, LOW);
  118.  
  119. }
  120. if (Koguprotsent <= 75){
  121.  
  122. digitalWrite(waterPump, LOW); // if moisture is 75 % water pump on. I have China relay block where LOW is on and HIGH is off
  123. delay(1000); //how many sec water pump is ON
  124. digitalWrite(waterPump, HIGH); // water pump OFF
  125.  
  126.  
  127. }
  128.  
  129. //---------- temp
  130. delay(1000);
  131. Serial.print("Getting temperatures...\n\r");
  132. sensors.requestTemperatures();
  133.  
  134. Serial.print("Inside temperature is: ");
  135. printTemperature(insideThermometer);
  136. Serial.print("\n\r");
  137. // Serial.print("Outside temperature is: ");
  138. // printTemperature(outsideThermometer);
  139. // Serial.print("\n\r");
  140. // Serial.print("Dog House temperature is: ");
  141. // printTemperature(dogHouseThermometer);
  142. // Serial.print("\n\r\n\r");
  143. }
  144.  
  145.  
  146.  
  147.  
  148. int SoilMoisture(){
  149. int reading;
  150. // set driver pins to outputs
  151. pinMode(divider_top,OUTPUT);
  152. pinMode(divider_bottom,OUTPUT);
  153.  
  154. // drive a current through the divider in one direction
  155. digitalWrite(divider_top,LOW);
  156. digitalWrite(divider_bottom,HIGH);
  157.  
  158. // wait a moment for capacitance effects to settle
  159. delay(1000);
  160.  
  161. // take a reading
  162. reading=analogRead(moisture_input);
  163.  
  164. // reverse the current
  165. digitalWrite(divider_top,HIGH);
  166. digitalWrite(divider_bottom,LOW);
  167.  
  168. // give as much time in 'reverse' as in 'forward'
  169. delay(1000);
  170.  
  171. // stop the current
  172. digitalWrite(divider_bottom,LOW);
  173.  
  174. return reading;
  175.  
  176. //relays for temp
  177. pinMode(tempHigh,OUTPUT);
  178.  
  179.  
  180.  
  181.  
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement