SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <DHT.h> | |
| 2 | #define BLYNK_PRINT Serial | |
| 3 | #include <BlynkSimpleEsp8266.h> | |
| 4 | #include <Wire.h> // Include I2C bus library | |
| 5 | #include <LiquidCrystal_I2C.h> // Include LCD-I2C bus library | |
| 6 | #define DHTPIN 13 //pin connect DHT | |
| 7 | //#define LED D10 //LED BUILTIN for NodeMCU | |
| 8 | #define DHTTYPE DHT11 //if use DHT11 edit to "DHT11" | |
| 9 | DHT dht(DHTPIN, DHTTYPE); | |
| 10 | LiquidCrystal_I2C lcd(0x27, 20, 4); | |
| 11 | ||
| 12 | char auth[] = "4cb8b10967134ba4a5797db23055c7e2";// You should get Auth Token in the Blynk App. | |
| 13 | char ssid[] = "TP-Link_Rajib_Deepi";// Your WiFi credentials. | |
| 14 | char pass[] = "sony@595";//Set password to "" for open networks. | |
| 15 | int MosLowLimit = 30; | |
| 16 | int MosHighLimit =60; | |
| 17 | int TempLimit = 25; | |
| 18 | int automatic = 1; | |
| 19 | ||
| 20 | BLYNK_WRITE(V0) // V5 is the number of Virtual Pin | |
| 21 | {
| |
| 22 | int AutoValue = param.asInt(); | |
| 23 | ||
| 24 | if (AutoValue == 1) | |
| 25 | {
| |
| 26 | automatic = 1; | |
| 27 | } | |
| 28 | else | |
| 29 | {
| |
| 30 | automatic = 0; | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | void setup() | |
| 35 | {
| |
| 36 | Blynk.begin(auth, ssid, pass); | |
| 37 | //timer.setInterval(2000, sendUptime); | |
| 38 | Serial.begin(115200); | |
| 39 | // pinMode(LED,OUTPUT); | |
| 40 | lcd.init(); | |
| 41 | lcd.setBacklight(HIGH); | |
| 42 | lcd.setCursor(0,0); | |
| 43 | //lcd.print("********************");
| |
| 44 | lcd.print(" Welcome ");
| |
| 45 | lcd.setCursor(0,1); | |
| 46 | lcd.print(" To ");
| |
| 47 | lcd.setCursor(0,2); | |
| 48 | lcd.print(" Smart ");
| |
| 49 | lcd.setCursor(0,3); | |
| 50 | lcd.print(" Agriculture System ");
| |
| 51 | delay(2000); | |
| 52 | ||
| 53 | } | |
| 54 | void loop() | |
| 55 | {
| |
| 56 | Blynk.run(); | |
| 57 | // *****************Moisture Control code.******************************************** | |
| 58 | int val = analogRead(A0); | |
| 59 | String message; // Initializing message | |
| 60 | //syntax:- map(value, fromLow, fromHigh, toLow, toHigh) | |
| 61 | val = map(val, 1023, 180, 0, 100); | |
| 62 | Serial.print("Soil Moisture");
| |
| 63 | Serial.println(abs(val)); | |
| 64 | // lcd.clear(); | |
| 65 | lcd.setCursor(0,1); | |
| 66 | lcd.print("Soil moisture: ");
| |
| 67 | lcd.setCursor(15,1); | |
| 68 | lcd.print(String(abs(val))); | |
| 69 | lcd.setCursor(17,1); | |
| 70 | lcd.print("% ");
| |
| 71 | //delay(100); | |
| 72 | ||
| 73 | //************************Start pump on auto mode***************************************** | |
| 74 | ||
| 75 | if ((abs(val) <= MosLowLimit)&& (automatic == 1)) | |
| 76 | {
| |
| 77 | digitalWrite(12, HIGH); | |
| 78 | Serial.println("Pump is On");
| |
| 79 | lcd.setCursor(0,2); | |
| 80 | lcd.print("Pump is On ");
| |
| 81 | } | |
| 82 | ||
| 83 | //******************************Stop pump on auto mode************************************* | |
| 84 | else if((abs(val)>= MosHighLimit) && (automatic == 1)) | |
| 85 | {
| |
| 86 | digitalWrite(12, LOW); | |
| 87 | Serial.println("Pump is Off");
| |
| 88 | lcd.setCursor(0,2); | |
| 89 | lcd.print("Pump is Off ");
| |
| 90 | } | |
| 91 | ||
| 92 | ||
| 93 | //*****************Temperature And Humidity read and Display********************************* | |
| 94 | ||
| 95 | // Reading temperature or humidity takes about 250 milliseconds! | |
| 96 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
| 97 | int h = dht.readHumidity(); | |
| 98 | int t = dht.readTemperature(); | |
| 99 | Blynk.virtualWrite(V5, int (h)); | |
| 100 | Blynk.virtualWrite(V6, int (t)); | |
| 101 | // check if returns are valid, if they are NaN (not a number) then something went wrong! | |
| 102 | ||
| 103 | if (isnan(t) || isnan(h)) | |
| 104 | {
| |
| 105 | Serial.println("Failed to read from Temp And Humid Senser");
| |
| 106 | lcd.setCursor(0,0); | |
| 107 | lcd.print("Check the Connection");
| |
| 108 | } | |
| 109 | else | |
| 110 | {
| |
| 111 | lcd.setCursor(0,0); | |
| 112 | lcd.print("Hum:");
| |
| 113 | lcd.setCursor(4,0); | |
| 114 | lcd.print(int(h)); | |
| 115 | lcd.setCursor(6,0); | |
| 116 | lcd.print("% ");
| |
| 117 | lcd.setCursor(9,0); | |
| 118 | lcd.print("Tem: ");
| |
| 119 | lcd.setCursor(13,0); | |
| 120 | lcd.print(t); | |
| 121 | lcd.setCursor(15,0); | |
| 122 | lcd.print("*C ");
| |
| 123 | } | |
| 124 | //*******************temperature controlled fan inauto mode ************ | |
| 125 | ||
| 126 | if((t > TempLimit)&& (automatic == 1)) | |
| 127 | {
| |
| 128 | digitalWrite(15, HIGH);//start cooling | |
| 129 | Serial.println("***Cooling On***");
| |
| 130 | lcd.setCursor(0,3); | |
| 131 | lcd.print("****Cooling On**** ");
| |
| 132 | } | |
| 133 | else if ((t < TempLimit)&& (automatic == 1)) | |
| 134 | {
| |
| 135 | digitalWrite(15, LOW); | |
| 136 | Serial.println("***Cooling Off***");
| |
| 137 | lcd.setCursor(0,3); | |
| 138 | lcd.print("****Cooling Off**** ");
| |
| 139 | } | |
| 140 | ||
| 141 | //*****************LCD update in Manual mode***************************** | |
| 142 | ||
| 143 | if(automatic == 0) //system is in manual update | |
| 144 | {
| |
| 145 | if(digitalRead(12) == HIGH) //check pump is on | |
| 146 | {
| |
| 147 | Serial.println("Pump is On");
| |
| 148 | lcd.setCursor(0,2); | |
| 149 | lcd.print("Pump is On ");
| |
| 150 | } | |
| 151 | else if(digitalRead(12) == LOW) // check pump is off | |
| 152 | {
| |
| 153 | Serial.println("Pump is Off");
| |
| 154 | lcd.setCursor(0,2); | |
| 155 | lcd.print("Pump is Off ");
| |
| 156 | } | |
| 157 | ||
| 158 | if(digitalRead(15) == HIGH) // check fan is ON | |
| 159 | {
| |
| 160 | Serial.println("***Cooling On***");
| |
| 161 | lcd.setCursor(0,3); | |
| 162 | lcd.print("****Cooling On**** ");
| |
| 163 | } | |
| 164 | else if(digitalRead(15) == LOW) // check fan is Off | |
| 165 | {
| |
| 166 | Serial.println("***Cooling Off***");
| |
| 167 | lcd.setCursor(0,3); | |
| 168 | lcd.print("****Cooling Off**** ");
| |
| 169 | } | |
| 170 | } | |
| 171 | } |