Guest User

Greenhouse project 2 with lcd

a guest
Jan 3rd, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.94 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. /*
  6. 0 - 232 rxd
  7. 1 - 232 txd
  8. 2 - enable (LCD) pin 6 on lcd
  9. 3 - temp sensor (LCD) RS pin 4 on lcd
  10. 4 - sd card 9 (ETHERNET SHIELD)
  11. 5 - lcd d4 (LCD)
  12. 6 - lcd d5 (LCD)
  13. 7 - lcd d6 (LCD)
  14. 8 - lcd d7 (LCD)
  15. 9
  16. 10 - w5100 select(ETHERNET SHIELD)
  17. 11 - SPI MOSI (ETHERNET SHIELD)
  18. 12 - SPI MISO (ETHERNET SHIELD)
  19. 13 - SPI CLK (ETHERNET SHIELD)
  20.  
  21. ANALOG
  22. 0 - MOISTURE in (analog)
  23. 1 - moisture (digital)
  24. 2 - moister 1 (digital)
  25. 3 - window open (digital)
  26. 4 - window close (digital)
  27. 5 - water pump (digital)
  28. */
  29.  
  30. //relay and moisture sensor
  31. //http://robocraft.ru/blog/arduino/444.html in russian
  32. //temperature from DS18B20
  33.  
  34.  
  35.  
  36.  
  37.  
  38. // initialize the library with the numbers of the interface pins
  39. LiquidCrystal lcd(8, 7, 6, 5, 3, 2,);
  40.  
  41. // Data wire is plugged into pin 9 on the Arduino
  42. #define ONE_WIRE_BUS 9
  43.  
  44. // Setup a oneWire instance to communicate with any OneWire devices
  45. OneWire oneWire(ONE_WIRE_BUS);
  46.  
  47. // Pass our oneWire reference to Dallas Temperature.
  48. DallasTemperature sensors(&oneWire);
  49.  
  50. // Assign the addresses of your 1-Wire temp sensors.
  51. // See the tutorial on how to obtain these addresses:
  52. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  53.  
  54. DeviceAddress insideThermometer = { 0x28, 0x2B, 0xE6, 0xDA, 0x02, 0x00, 0x00, 0x43 };
  55. //DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
  56. //DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };
  57.  
  58. #define moisture_input 0 // analog pin 0
  59. #define divider_top 9 // moisture resistor digital pin 9
  60. #define divider_bottom 10 // moisture sensor 1 digital pin 10
  61. int waterPump =7; // led, water pump digital pin 7
  62. int moisture;
  63. int Koguprotsent; //moisture % in Estonian
  64. int tempHigh =6; // relay who open window
  65. int tempLow =5; //relay who close window
  66.  
  67. int X=0;
  68.  
  69. void setup(void)
  70. {
  71.  
  72. pinMode (tempLow, OUTPUT);
  73. pinMode (tempHigh, OUTPUT);
  74. pinMode (waterPump, OUTPUT);
  75. digitalWrite(waterPump, LOW);
  76. digitalWrite (tempLow, LOW);
  77. digitalWrite (tempHigh, LOW);
  78. // start serial port
  79. Serial.begin(9600);
  80. // Start up the library
  81. sensors.begin();
  82. // set the resolution to 10 bit (good enough?)
  83. sensors.setResolution(insideThermometer, 10);
  84. // sensors.setResolution(outsideThermometer, 10);
  85. // sensors.setResolution(dogHouseThermometer, 10);
  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("C: ");
  95. Serial.print(tempC);
  96. //-- panin koodi siia..,comment in estonian means nothing, only for me
  97. }
  98.  
  99. if (tempC >= 27 && X ==0){ // if temp => 27 window opened
  100. digitalWrite(tempHigh, HIGH);
  101. delay(6000);
  102. digitalWrite(tempHigh, LOW);
  103. X = 1;
  104. }
  105.  
  106. if (tempC <= 24 && X ==1){ // if temp <= 24 window close
  107.  
  108. X = 0;
  109.  
  110. digitalWrite(tempLow, HIGH);
  111. delay(6000);
  112. digitalWrite(tempLow, LOW);
  113. }
  114.  
  115.  
  116.  
  117.  
  118. // Serial.print(" F: ");
  119. // Serial.print(DallasTemperature::toFahrenheit(tempC));
  120.  
  121. }
  122.  
  123. void loop(void)
  124. {
  125. //---- soil
  126.  
  127. // Serial.print("Getting Soil Moisture...\n\r");
  128. moisture=SoilMoisture(); // soilmoister as variable
  129. Koguprotsent = ((moisture*100)/970); // my moisture max value sensors in water was 950
  130. Serial.print("Sensors moisture value: ");
  131. Serial.println(moisture);
  132.  
  133. Serial.print("Moisture is ");
  134. Serial.print(Koguprotsent);
  135. Serial.print(" % ");
  136.  
  137. Serial.println();
  138.  
  139.  
  140. delay(1000); // pause 1 sec.
  141.  
  142.  
  143.  
  144. if (Koguprotsent >= 90){ //if moisture is 90 % water pump off
  145.  
  146. digitalWrite(waterPump, LOW);
  147.  
  148. }
  149. if (Koguprotsent <= 75){ // if moisture is 75 % water pump on. I have China relay block where LOW is on and HIGH is off
  150.  
  151. digitalWrite(waterPump, LOW);
  152. delay(1000); //how many sec water pump is ON
  153. digitalWrite(waterPump, HIGH); // water pump OFF
  154.  
  155.  
  156. }
  157.  
  158. //---------- temp
  159. delay(1000);
  160. Serial.print("Getting temperatures...\n\r");
  161. sensors.requestTemperatures();
  162.  
  163. Serial.print("Inside temperature is: ");
  164. printTemperature(insideThermometer);
  165. Serial.print("\n\r");
  166. // Serial.print("Outside temperature is: ");
  167. // printTemperature(outsideThermometer);
  168. // Serial.print("\n\r");
  169. // Serial.print("Dog House temperature is: ");
  170. // printTemperature(dogHouseThermometer);
  171. // Serial.print("\n\r\n\r");
  172. }
  173.  
  174.  
  175.  
  176.  
  177. int SoilMoisture(){
  178. int reading;
  179. // set driver pins to outputs
  180. pinMode(divider_top,OUTPUT);
  181. pinMode(divider_bottom,OUTPUT);
  182.  
  183. // drive a current through the divider in one direction
  184. digitalWrite(divider_top,LOW);
  185. digitalWrite(divider_bottom,HIGH);
  186.  
  187. // wait a moment for capacitance effects to settle
  188. delay(1000);
  189.  
  190. // take a reading
  191. reading=analogRead(moisture_input);
  192.  
  193. // reverse the current
  194. digitalWrite(divider_top,HIGH);
  195. digitalWrite(divider_bottom,LOW);
  196.  
  197. // give as much time in 'reverse' as in 'forward'
  198. delay(1000);
  199.  
  200. // stop the current
  201. digitalWrite(divider_bottom,LOW);
  202.  
  203. return reading;
  204.  
  205. // //relays for temp
  206. pinMode(tempHigh,OUTPUT);
  207.  
  208.  
  209.  
  210.  
  211.  
  212. }
  213.  
  214.  
  215. void setup() {
  216. // declare pin 9 to be an output:
  217. pinMode(9, OUTPUT);
  218. analogWrite(9, 50);
  219. // set up the LCD's number of columns and rows:
  220. lcd.begin(16, 2);
  221. lcd.setCursor(0,0);
  222. // Print a message to the LCD.
  223. lcd.print("Temperature is ");
  224. lcd.print("\n\r");
  225.  
  226. lcd.setCursor(0,1);
  227.  
  228. lcd.print("Moisture is ");
  229. lcd.print(Koguprotsent);
  230. lcd.print(" % ");
  231.  
  232. delay(3000);
  233.  
  234. lcd.clear();
  235.  
  236. lcd.print("Sensors moisture value: ");
  237. lcd.println(moisture);
  238.  
  239.  
  240.  
  241.  
  242.  
  243. }
Advertisement
Add Comment
Please, Sign In to add comment