Advertisement
Guest User

Tarım otomasyon arduino kodu

a guest
Sep 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3. #include <dht.h>
  4.  
  5. char blueToothVal;
  6. int serialInt = 0;
  7. int fan = 7;
  8. int water = 8;
  9. int moisture = 0;
  10. boolean autoMod = false;
  11. boolean set = false;
  12. boolean maxTempB = false;
  13. boolean minTempB = false;
  14. boolean maxMoisB = false;
  15. boolean minMoisB = false;
  16. int maxTemp = 30;
  17. int maxMois = 400;
  18. int minTemp = 20;
  19. int minMois = 150;
  20.  
  21. RTC_DS1307 RTC;
  22. dht DHT;
  23.  
  24. #define DHT11_PIN 2
  25.  
  26. void setup() {
  27. Wire.begin();
  28. RTC.begin();
  29. pinMode(fan, OUTPUT);
  30. pinMode(water, OUTPUT);
  31. Serial.begin(9600);
  32. digitalWrite(fan, LOW);
  33. digitalWrite(water, LOW);
  34. }
  35.  
  36. void loop() {
  37. if(autoMod){
  38. if(!digitalRead(fan) && DHT.temperature > maxTemp){
  39. digitalWrite(fan, HIGH);
  40. }
  41. else if(digitalRead(fan) && DHT.temperature < minTemp){
  42. digitalWrite(fan, LOW);
  43. }
  44. }
  45.  
  46. if(Serial.available()){
  47. blueToothVal=Serial.read();
  48. serialInt = Serial.parseInt();
  49. }
  50. if(blueToothVal != 0 || serialInt != 0){
  51. if(!set){
  52. if (blueToothVal=='u'){
  53. getUpdate();
  54. }
  55. else if(blueToothVal=='f' && !autoMod){
  56. if(!digitalRead(fan)){
  57. digitalWrite(fan, HIGH);
  58. Serial.println("Fan is On");
  59. }
  60. else if(digitalRead(fan)){
  61. digitalWrite(fan, LOW);
  62. Serial.println("Fan is Off");
  63. }
  64.  
  65. blueToothVal = 0;
  66. }
  67.  
  68. else if(blueToothVal=='w' && !autoMod){
  69. if(!digitalRead(water)){
  70. digitalWrite(water, HIGH);
  71. Serial.println("Water is On");
  72. }
  73. else if(digitalRead(water)){
  74. digitalWrite(water, LOW);
  75. Serial.println("Water is Off");
  76. }
  77.  
  78. blueToothVal = 0;
  79. }
  80.  
  81. else if(blueToothVal=='a'){
  82. if(autoMod){
  83. autoMod = false;
  84. }
  85. else if(!autoMod){
  86. autoMod = true;
  87. }
  88. getUpdate();
  89. blueToothVal = 0;
  90. }
  91.  
  92. else if(blueToothVal=='s'){
  93. set = true;
  94. Serial.println("W/F");
  95. blueToothVal = 0;
  96. }
  97. }
  98. else if(set){
  99. if(minTempB){
  100. if(serialInt < maxTemp){
  101. minTemp = serialInt;
  102. serialInt = 0;
  103. minTempB = false;
  104. set = false;
  105. Serial.println(minTemp);
  106. }
  107. else{
  108. Serial.println("please enter a smaller value than max temperature!");
  109. serialInt = 0;
  110. }
  111. }
  112.  
  113. else if(maxTempB){
  114. maxTemp = serialInt;
  115. serialInt = 0;
  116. maxTempB = false;
  117. minTempB = true;
  118. Serial.println(maxTemp);
  119. Serial.println("Give min Temperature value.");
  120. }
  121.  
  122. else if(minMoisB){
  123. if(serialInt < maxMois){
  124. minMois = serialInt;
  125. serialInt = 0;
  126. minMoisB = false;
  127. set = false;
  128. Serial.println(minMois);
  129. }
  130. else{
  131. Serial.println("please enter a smaller value than max moisture!");
  132. serialInt = 0;
  133. }
  134. }
  135.  
  136. else if(maxMoisB){
  137. maxMois = serialInt;
  138. serialInt = 0;
  139. maxMoisB = false;
  140. minMoisB = true;
  141. Serial.println(maxMois);
  142. Serial.println("Give min Moisture value.");
  143. }
  144.  
  145.  
  146. if(blueToothVal == 'f'){
  147. Serial.println("Give max Temperature value.");
  148. maxTempB = true;
  149. }
  150.  
  151. else if(blueToothVal == 'w'){
  152. Serial.println("Give max Moisture value.");
  153. maxMoisB = true;
  154. }
  155. blueToothVal = 0;
  156. }
  157. }
  158. }
  159.  
  160. void getUpdate(){
  161. DateTime now = RTC.now();
  162. Serial.print(now.year(), DEC);
  163. Serial.print("/");
  164. Serial.print(now.month(), DEC);
  165. Serial.print("/");
  166. Serial.print(now.day(), DEC);
  167. Serial.print(" ");
  168. Serial.print(now.hour(), DEC);
  169. Serial.print(":");
  170. Serial.print(now.minute(), DEC);
  171. Serial.print(":");
  172. Serial.print(now.second(), DEC);
  173. Serial.println();
  174. int chk = DHT.read11(DHT11_PIN);
  175. if(DHT.temperature > -30){
  176. Serial.print("Temperature = ");
  177. Serial.println(DHT.temperature);
  178. Serial.print("Humidity = ");
  179. Serial.println(DHT.humidity);
  180. Serial.print("Auto Mod = ");
  181. Serial.println(autoMod);
  182. Serial.println();
  183. Serial.print("Max Temp = ");
  184. Serial.println(maxTemp);
  185. Serial.print("Min Temp = ");
  186. Serial.println(minTemp);
  187. Serial.println();
  188. Serial.print("Max Mois = ");
  189. Serial.println(maxMois);
  190. Serial.print("Min Mois = ");
  191. Serial.println(minMois);
  192. Serial.println();
  193. blueToothVal = 0;
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement