Advertisement
seston

Greenhouse_h-bridge_20x4lcd

Jan 4th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <LiquidCrystal.h>
  3. #include <DallasTemperature.h>
  4. #include <DHT.h>
  5.  
  6.  
  7.  
  8. #define DHTPIN 7 // what pin we're connected to D7
  9. // Uncomment whatever type you're using!
  10. //#define DHTTYPE DHT11 // DHT 11
  11. #define DHTTYPE DHT22 // DHT 22 (AM2302)
  12. //#define DHTTYPE DHT21 // DHT 21 (AM2301)
  13. DHT dht(DHTPIN, DHTTYPE);
  14.  
  15.  
  16. /*LCD 20x4 pins for Mega
  17. 1- GND
  18. 2- +5V
  19. 3- GND in my 20x4 lcd contrast
  20. 4- D22
  21. 5- GND
  22. 6- D24
  23. 7- NC
  24. 8- NC
  25. 9- NC
  26. 10- NC
  27. 11- D26
  28. 12- D28
  29. 13- D30
  30. 14- D32
  31. 15- NC
  32. 16- NC
  33.  
  34. pins D8, D9 for first h-bridge, for motor nr.1 what open and close window nr.1
  35. I used Stepper-Motor-Drive-Controller-Board-Module-L298N-Dual-H-Bridge-DC-For-Arduino
  36. in bridged mode In1+In3 and In2+In4 is bridged and outputs 1-3 and 2-4 is bridged for 4A
  37. current
  38. */
  39.  
  40. LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
  41.  
  42.  
  43. // Data wire is plugged into pin D2 on the Arduino
  44. #define ONE_WIRE_BUS 2
  45.  
  46.  
  47. // Setup a oneWire instance to communicate with any OneWire devices
  48. OneWire oneWire(ONE_WIRE_BUS);
  49.  
  50. // Pass our oneWire reference to Dallas Temperature.
  51. DallasTemperature sensors(&oneWire);
  52.  
  53. // Assign the addresses of your 1-Wire temp sensors.
  54. // See the tutorial on how to obtain these addresses:
  55. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  56. //sensors.getAddress(deviceAddress, index)
  57. //DeviceAddress pinnaseThermometer = { 0x28, 0x0A, 0x03, 0xD9, 0x04, 0x00, 0x00, 0x93 };
  58. DeviceAddress kasvuhoonesThermometer = { 0x28, 0xEA, 0xD6, 0xBB, 0x05, 0x00, 0x00, 0x0A };
  59. DeviceAddress outdoorThermometer = { 0x28, 0xBB, 0xF1, 0xBB, 0x05, 0x00, 0x00, 0xBA };
  60. //DeviceAddress mullasThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
  61.  
  62.  
  63.  
  64. int tempHigh =A3; // relee mis avab luugi i do not use this time
  65. int tempLow =A4; //relee mis suleb luugi, i do not use this time
  66. //int MOTOR1 =8;
  67. //int MOTOR2 =9;
  68.  
  69. int X=0;
  70.  
  71. void setup(void)
  72. {
  73.  
  74. lcd.begin(20, 4);
  75. lcd.clear();
  76. //lcd.setCursor(0,0);
  77.  
  78. pinMode (tempLow, OUTPUT);
  79. pinMode (tempHigh, OUTPUT);
  80. //pinMode (MOTOR1. OUTPUT); //for motor 1
  81. //pinMode (MOTOR2, OUTPUT); //for motor1
  82.  
  83. digitalWrite (tempLow, HIGH);
  84. digitalWrite (tempHigh, HIGH);
  85.  
  86.  
  87. // start serial port
  88. Serial.begin(9600);
  89.  
  90.  
  91. // Start up the library
  92. sensors.begin();
  93. // set the resolution to 10 bit (good enough?)
  94. //sensors.setResolution(pinnaseThermometer, 9);
  95. sensors.setResolution(kasvuhoonesThermometer, 9); //greenhouse
  96. sensors.setResolution(outdoorThermometer, 9);
  97. //sensors.setResolution(mullasThermometer, 9);
  98.  
  99. }
  100.  
  101. void printTemperature(DeviceAddress deviceAddress)
  102. {
  103. float tempC = sensors.getTempC(outdoorThermometer);
  104. float tempC1 = sensors.getTempC(kasvuhoonesThermometer); // temp in greenhouse
  105. if (tempC == -127.00) {
  106. Serial.print("Error getting temperature");
  107. } else {
  108. Serial.print(tempC);
  109. Serial.print(tempC1);
  110. Serial.print("C ");
  111. lcd.setCursor(11, 1);
  112. lcd.print("Out:");
  113. lcd.print(tempC ,1);
  114. lcd.print("C");
  115. lcd.setCursor(0,1);
  116. lcd.print("In:");
  117. lcd.print(tempC1 ,1);
  118. lcd.print("C");
  119.  
  120. //-- panin koodi siia..
  121. }
  122.  
  123. Serial.println();
  124. if (tempC >= 27 && X ==0){
  125. digitalWrite(tempHigh, HIGH);
  126. digitalWrite(8, HIGH); //start open window pin for H-bridge 1
  127. digitalWrite(9, LOW); // start open window pin for H-bridge 1
  128. Serial.print("Palav on liiga.Avame luugi.");//fucking warm, i open windows
  129. lcd.setCursor(0,0);
  130. lcd.print(" Avame luugi");
  131. delay(6000); //time for h-bridge to open window
  132. digitalWrite(tempHigh, LOW);
  133. digitalWrite(8, LOW); // stop motor, pin for H-bridge 1
  134. digitalWrite(9, LOW); // stop motor, pin for H-bridge 1
  135. lcd.setCursor(0,0);
  136.  
  137. lcd.print(" Luuk on avatud"); //window is open
  138. X = 1;
  139. }
  140.  
  141. if (tempC <= 26 && X ==1){
  142. Serial.print("Jahedaks kisub.Sulgeme luugi"); //this means, weather is cold and needed close window
  143.  
  144. lcd.setCursor(0, 0);
  145. lcd.print(" Sulgeme luugi"); //start close window
  146. Serial.print(tempC);
  147. Serial.print("C ");
  148. lcd.setCursor(0, 1);
  149. lcd.print("Out:");
  150. lcd.print(tempC ,1);
  151. lcd.print("C");
  152.  
  153. X = 0;
  154.  
  155. digitalWrite(tempLow, HIGH);
  156.  
  157. digitalWrite(8, LOW); //start close window pin for H-bridge 1
  158. digitalWrite(9, HIGH); // start clse window pin for H-bridge 1
  159. delay(6000); // time for h-bridge close window
  160. digitalWrite(tempLow, LOW);
  161. digitalWrite(8, LOW); //stop close window pin for H-bridge 1
  162. digitalWrite(9, LOW); // stop close window pin for H-bridge 1
  163. lcd.setCursor(0,0);
  164. lcd.print(" Luuk on suletud"); //window is closed
  165.  
  166.  
  167.  
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. }
  176.  
  177. void loop(void)
  178. {
  179.  
  180. float h = dht.readHumidity();
  181. float t = dht.readTemperature();
  182.  
  183. // check if returns are valid, if they are NaN (not a number) then something went wrong!
  184. if (isnan(t) || isnan(h)) {
  185. Serial.println("Failed to read from DHT");
  186. } else {
  187. Serial.print("Humidity: ");
  188. Serial.print(h);
  189. Serial.print(" %\t");
  190. Serial.print("Temperature: ");
  191. Serial.print(t);
  192. Serial.println(" *C");
  193. lcd.setCursor(7,2);
  194. lcd.print("DHT22");
  195. lcd.setCursor(0,3);
  196. lcd.print("H:");
  197. lcd.print(h ,1);
  198. lcd.print("% ");
  199. lcd.print(" T:");
  200. lcd.print(t ,1);
  201. lcd.print("*C");
  202. }
  203.  
  204.  
  205.  
  206. //---------- temp
  207. delay(1000);
  208. Serial.print("Getting temperatures...\n\r");
  209. sensors.requestTemperatures();
  210. delay(2000);
  211. /*
  212. Serial.print("Mulla temperature is: ");
  213. printTemperature(pinnaseThermometer);
  214. Serial.print("\n\r");
  215. delay(1000);
  216. */
  217.  
  218. Serial.print("Kasvuhoones temperature is: ");
  219. printTemperature(kasvuhoonesThermometer);
  220. Serial.print("\n\r");
  221. delay(1000);
  222.  
  223. Serial.print("Outdoor temperature is: ");
  224. printTemperature(outdoorThermometer);
  225. Serial.print("\n\r");
  226. delay(1000);
  227.  
  228. /*
  229. Serial.print("Mullas temperature is: ");
  230. printTemperature(mullasThermometer);
  231. Serial.print("\n\r");
  232. delay(1000);
  233. */
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement