Guest User

SmartIrrigationv1.3

a guest
Aug 9th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. #define TINY_GSM_MODEM_SIM800
  2. #include <TinyGsmClientSIM800.h>
  3. #include <Blynk.h>
  4. #include <TinyGsmClient.h>
  5. #include <BlynkSimpleSIM800.h>
  6. #include <DHT.h>
  7. #include <Wire.h>
  8. #include <LiquidCrystal_I2C.h>
  9. #include <SoftwareSerial.h>
  10.  
  11. // Default heartbeat interval for GSM is 60
  12. // If you want override this value, uncomment and set this option:
  13. //#define BLYNK_HEARTBEAT 30
  14. #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
  15.  
  16. #define DHTPIN 7 // what pin we're connected to
  17. #define DHTTYPE DHT11 // DHT 11
  18. DHT dht(DHTPIN, DHTTYPE);
  19. //Set the pins on the I2C chip used for LCD connections
  20. //ADDR,EN,RS,D4,D5,D6,D7
  21. //LiquidCrystal lcd(0x27,2,3,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
  22. LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
  23.  
  24. int relay=8; // Relay for Pump pin
  25. const int relay1 = 12; // Relay for fan pin
  26.  
  27. // You should get Auth Token in the Blynk App.
  28. // Go to the Project Settings (nut icon).
  29. char auth[] = "5cee93f2433849739552a0d0afc852f2";
  30. // Your GPRS credentials
  31. // Leave empty, if missing user or pass
  32. char apn[] = "internet"; //APN of your service provider
  33. char user[] = "";
  34. char pass[] = "";
  35.  
  36. SoftwareSerial SerialAT(2, 3); // RX, TX
  37. TinyGsm modem(SerialAT);
  38.  
  39.  
  40.  
  41. void setup() {
  42. // initialize serial communication at 9600 bits per second:
  43. Serial.begin(9600);
  44. pinMode(relay, OUTPUT);
  45.  
  46. // Initializing LDC 20x4 module
  47. lcd.begin (20,4); // 20 x 4 LCD module
  48. lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
  49. lcd.setBacklight(HIGH);
  50. lcd.setCursor(0,1);
  51. lcd.print("Welcome To Smart Agriculture System");
  52. lcd.setCursor(0,2);
  53. lcd.autoscroll();
  54. delay(2000);
  55.  
  56.  
  57. // set console baud rate
  58. // Serial.begin(19200);
  59. // delay(10);
  60.  
  61. // Set GSM module baud rate
  62. //SerialAT.begin(19200);
  63. //delay(3000);
  64.  
  65. // Restart takes quite some time
  66. // To skip it, call init() instead of restart()
  67. modem.restart();
  68.  
  69. // Unlock your SIM card with a PIN
  70. //modem.simUnlock("1234");
  71.  
  72. Blynk.begin(auth, modem, apn, user, pass);
  73. }
  74.  
  75.  
  76. void loop() {
  77. // *****************Moisture Control code.********************************************
  78. //read the input on analog pin 0:
  79. int sensorValue = analogRead(A0);
  80. Serial.println(sensorValue);
  81. delay(1000);
  82. //Getting data in percentage
  83. int val = analogRead(A0);
  84. String message=""; // Initializing message
  85. val = map(val, 1023, 180, 0, 100); //syntax:- map(value, fromLow, fromHigh, toLow, toHigh)
  86. if (abs(val) <= 30)
  87. {
  88. digitalWrite(relay, HIGH);
  89. message=String("Starting Pump.Soil Moisture % is :");
  90. message+=val;
  91. Serial.println(message);
  92. lcd.clear();
  93. lcd.setCursor(0,1);
  94. lcd.print(message);
  95. lcd.autoscroll();
  96. delay(5000);
  97.  
  98. }
  99.  
  100. else if(abs(val)>=60)
  101. {
  102. digitalWrite(relay, LOW);
  103. message=String("**Good News** Turning Off the Pump as Soil Moisture Level has reached to safer level % :: ");
  104. message+=val;
  105. Serial.println(message);
  106. lcd.clear();
  107. lcd.setCursor(0,1);
  108. lcd.print(message);
  109. lcd.autoscroll();
  110. delay(8000);
  111.  
  112. }
  113. else if(30 <=abs(val)<=60)
  114. {
  115. message=String("Current Soil Moisture Level % is :: ");
  116. message+=val;
  117. Serial.println(message);
  118. lcd.clear();
  119. lcd.setCursor(0,1);
  120. lcd.print(message);
  121. lcd.autoscroll();
  122. delay(3000);
  123. }
  124.  
  125. //***********************************************Temperature And Humidity Display*********************************
  126.  
  127. // Reading temperature or humidity takes about 250 milliseconds!
  128. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  129. float h = dht.readHumidity();
  130. float t = dht.readTemperature();
  131.  
  132. // check if returns are valid, if they are NaN (not a number) then something went wrong!
  133.  
  134. if (isnan(t) || isnan(h))
  135. {
  136. Serial.println("Failed to read from Temp And Humid Senser");
  137. }
  138. else {
  139. lcd.clear();
  140. lcd.setCursor(0, 1);
  141. lcd.print("Hum: ");
  142. lcd.print(h);
  143. lcd.print("%");
  144. delay(2000);
  145. lcd.clear();
  146. lcd.setCursor(0, 1);
  147. lcd.print("Tem: ");
  148. lcd.print(t);
  149. lcd.print("*C");
  150. delay(2000);
  151.  
  152. if(t > 30){
  153. digitalWrite(relay1, HIGH);//start cooling
  154. message=String("Turning On Cooling System as temp is *c :: ");
  155. message+=t;
  156. Serial.println(message);
  157. lcd.clear();
  158. lcd.setCursor(0,1);
  159. lcd.print(message);
  160. lcd.autoscroll();
  161. delay(8000);}
  162. else{
  163. digitalWrite(relay1, LOW);
  164. message=String("Turning off Cooling System as temp is *c :: ");
  165. message+=t;
  166. Serial.println(message);
  167. lcd.clear();
  168. lcd.setCursor(0,1);
  169. lcd.print(message);
  170. lcd.autoscroll();
  171. delay(8000);}
  172.  
  173. }
  174.  
  175. //*******Code for GSM ********************************
  176.  
  177. Blynk.run();
  178.  
  179. // Check if any reads failed and exit early (to try again).
  180. if (isnan(h) || isnan(t)) {
  181. Serial.println("Failed to read from DHT sensor!");
  182. }
  183. else{
  184. // You can delete the following Serial.print's, it's just for debugging purposes
  185. Serial.print("Humidity: ");
  186. Serial.print(h);
  187. Serial.print(" %\t Temperature: ");
  188. Serial.print(t);
  189. Serial.print(" *C ");
  190. Serial.print("Humidity: ");
  191. Serial.print(h);
  192. Serial.print(" %\t Temperature: ");
  193. Serial.print(t);
  194. Serial.print(" *C ");
  195. Blynk.virtualWrite(V1,t);
  196. Blynk.virtualWrite(V2,h);
  197. Blynk.virtualWrite(V3,abs(val));
  198. if(t>30) //set temperatur level for notification
  199. {
  200. Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Temperature Increased over limit");
  201. Blynk.notify("Temperature Increased over limit (> 35 *c");
  202. }
  203. if(h>60) //set Humid level for notification
  204. {
  205. Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Humidity Increased over limit");
  206. Blynk.notify("Humidity Increased over limit(> 70%)");
  207. }
  208. if(abs(val)<30) //set Moisture level for notification
  209. {
  210. Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Humidity Increased over limit");
  211. Blynk.notify("Moisture Reduced to critical limit (< 30 %)");
  212. }
  213.  
  214. }
  215.  
  216. }
Add Comment
Please, Sign In to add comment