Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DHT.h>
- #define BLYNK_PRINT Serial
- #include <BlynkSimpleEsp8266.h>
- #include <Wire.h> // Include I2C bus library
- #include <LiquidCrystal_I2C.h> // Include LCD-I2C bus library
- #define DHTPIN 13 //pin connect DHT
- //#define LED D10 //LED BUILTIN for NodeMCU
- #define DHTTYPE DHT11 //if use DHT11 edit to "DHT11"
- DHT dht(DHTPIN, DHTTYPE);
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- char auth[] = "4cb8b10967134ba4a5797db23055c7e2";// You should get Auth Token in the Blynk App.
- char ssid[] = "TP-Link_Rajib_Deepi";// Your WiFi credentials.
- char pass[] = "sony@595";//Set password to "" for open networks.
- int MosLowLimit = 30;
- int MosHighLimit =60;
- int TempLimit = 25;
- int automatic = 1;
- BLYNK_WRITE(V0) // V5 is the number of Virtual Pin
- {
- int AutoValue = param.asInt();
- if (AutoValue == 1)
- {
- automatic = 1;
- }
- else
- {
- automatic = 0;
- }
- }
- void setup()
- {
- Blynk.begin(auth, ssid, pass);
- //timer.setInterval(2000, sendUptime);
- Serial.begin(115200);
- // pinMode(LED,OUTPUT);
- lcd.init();
- lcd.setBacklight(HIGH);
- lcd.setCursor(0,0);
- //lcd.print("********************");
- lcd.print(" Welcome ");
- lcd.setCursor(0,1);
- lcd.print(" To ");
- lcd.setCursor(0,2);
- lcd.print(" Smart ");
- lcd.setCursor(0,3);
- lcd.print(" Agriculture System ");
- delay(2000);
- }
- void loop()
- {
- Blynk.run();
- // *****************Moisture Control code.********************************************
- int val = analogRead(A0);
- String message; // Initializing message
- //syntax:- map(value, fromLow, fromHigh, toLow, toHigh)
- val = map(val, 1023, 180, 0, 100);
- Serial.print("Soil Moisture");
- Serial.println(abs(val));
- // lcd.clear();
- lcd.setCursor(0,1);
- lcd.print("Soil moisture: ");
- lcd.setCursor(15,1);
- lcd.print(String(abs(val)));
- lcd.setCursor(17,1);
- lcd.print("% ");
- //delay(100);
- //************************Start pump on auto mode*****************************************
- if ((abs(val) <= MosLowLimit)&& (automatic == 1))
- {
- digitalWrite(12, HIGH);
- Serial.println("Pump is On");
- lcd.setCursor(0,2);
- lcd.print("Pump is On ");
- }
- //******************************Stop pump on auto mode*************************************
- else if((abs(val)>= MosHighLimit) && (automatic == 1))
- {
- digitalWrite(12, LOW);
- Serial.println("Pump is Off");
- lcd.setCursor(0,2);
- lcd.print("Pump is Off ");
- }
- //*****************Temperature And Humidity read and Display*********************************
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- int h = dht.readHumidity();
- int t = dht.readTemperature();
- Blynk.virtualWrite(V5, int (h));
- Blynk.virtualWrite(V6, int (t));
- // check if returns are valid, if they are NaN (not a number) then something went wrong!
- if (isnan(t) || isnan(h))
- {
- Serial.println("Failed to read from Temp And Humid Senser");
- lcd.setCursor(0,0);
- lcd.print("Check the Connection");
- }
- else
- {
- lcd.setCursor(0,0);
- lcd.print("Hum:");
- lcd.setCursor(4,0);
- lcd.print(int(h));
- lcd.setCursor(6,0);
- lcd.print("% ");
- lcd.setCursor(9,0);
- lcd.print("Tem: ");
- lcd.setCursor(13,0);
- lcd.print(t);
- lcd.setCursor(15,0);
- lcd.print("*C ");
- }
- //*******************temperature controlled fan inauto mode ************
- if((t > TempLimit)&& (automatic == 1))
- {
- digitalWrite(15, HIGH);//start cooling
- Serial.println("***Cooling On***");
- lcd.setCursor(0,3);
- lcd.print("****Cooling On**** ");
- }
- else if ((t < TempLimit)&& (automatic == 1))
- {
- digitalWrite(15, LOW);
- Serial.println("***Cooling Off***");
- lcd.setCursor(0,3);
- lcd.print("****Cooling Off**** ");
- }
- //*****************LCD update in Manual mode*****************************
- if(automatic == 0) //system is in manual update
- {
- if(digitalRead(12) == HIGH) //check pump is on
- {
- Serial.println("Pump is On");
- lcd.setCursor(0,2);
- lcd.print("Pump is On ");
- }
- else if(digitalRead(12) == LOW) // check pump is off
- {
- Serial.println("Pump is Off");
- lcd.setCursor(0,2);
- lcd.print("Pump is Off ");
- }
- if(digitalRead(15) == HIGH) // check fan is ON
- {
- Serial.println("***Cooling On***");
- lcd.setCursor(0,3);
- lcd.print("****Cooling On**** ");
- }
- else if(digitalRead(15) == LOW) // check fan is Off
- {
- Serial.println("***Cooling Off***");
- lcd.setCursor(0,3);
- lcd.print("****Cooling Off**** ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement