Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TINY_GSM_MODEM_SIM800
- #include <TinyGsmClientSIM800.h>
- #include <Blynk.h>
- #include <TinyGsmClient.h>
- #include <BlynkSimpleSIM800.h>
- #include <DHT.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <SoftwareSerial.h>
- // Default heartbeat interval for GSM is 60
- // If you want override this value, uncomment and set this option:
- //#define BLYNK_HEARTBEAT 30
- #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
- #define DHTPIN 7 // what pin we're connected to
- #define DHTTYPE DHT11 // DHT 11
- DHT dht(DHTPIN, DHTTYPE);
- //Set the pins on the I2C chip used for LCD connections
- //ADDR,EN,RS,D4,D5,D6,D7
- //LiquidCrystal lcd(0x27,2,3,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
- LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
- int relay=8; // Relay for Pump pin
- const int relay1 = 12; // Relay for fan pin
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "5cee93f2433849739552a0d0afc852f2";
- // Your GPRS credentials
- // Leave empty, if missing user or pass
- char apn[] = "internet"; //APN of your service provider
- char user[] = "";
- char pass[] = "";
- SoftwareSerial SerialAT(2, 3); // RX, TX
- TinyGsm modem(SerialAT);
- void setup() {
- // initialize serial communication at 9600 bits per second:
- Serial.begin(9600);
- pinMode(relay, OUTPUT);
- // Initializing LDC 20x4 module
- lcd.begin (20,4); // 20 x 4 LCD module
- lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
- lcd.setBacklight(HIGH);
- lcd.setCursor(0,1);
- lcd.print("Welcome To Smart Agriculture System");
- lcd.setCursor(0,2);
- lcd.autoscroll();
- delay(2000);
- // set console baud rate
- // Serial.begin(19200);
- // delay(10);
- // Set GSM module baud rate
- //SerialAT.begin(19200);
- //delay(3000);
- // Restart takes quite some time
- // To skip it, call init() instead of restart()
- modem.restart();
- // Unlock your SIM card with a PIN
- //modem.simUnlock("1234");
- Blynk.begin(auth, modem, apn, user, pass);
- }
- void loop() {
- // *****************Moisture Control code.********************************************
- //read the input on analog pin 0:
- int sensorValue = analogRead(A0);
- Serial.println(sensorValue);
- delay(1000);
- //Getting data in percentage
- int val = analogRead(A0);
- String message=""; // Initializing message
- val = map(val, 1023, 180, 0, 100); //syntax:- map(value, fromLow, fromHigh, toLow, toHigh)
- if (abs(val) <= 30)
- {
- digitalWrite(relay, HIGH);
- message=String("Starting Pump.Soil Moisture % is :");
- message+=val;
- Serial.println(message);
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(message);
- lcd.autoscroll();
- delay(5000);
- }
- else if(abs(val)>=60)
- {
- digitalWrite(relay, LOW);
- message=String("**Good News** Turning Off the Pump as Soil Moisture Level has reached to safer level % :: ");
- message+=val;
- Serial.println(message);
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(message);
- lcd.autoscroll();
- delay(8000);
- }
- else if(30 <=abs(val)<=60)
- {
- message=String("Current Soil Moisture Level % is :: ");
- message+=val;
- Serial.println(message);
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(message);
- lcd.autoscroll();
- delay(3000);
- }
- //***********************************************Temperature And Humidity Display*********************************
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- // 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");
- }
- else {
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Hum: ");
- lcd.print(h);
- lcd.print("%");
- delay(2000);
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Tem: ");
- lcd.print(t);
- lcd.print("*C");
- delay(2000);
- if(t > 30){
- digitalWrite(relay1, HIGH);//start cooling
- message=String("Turning On Cooling System as temp is *c :: ");
- message+=t;
- Serial.println(message);
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(message);
- lcd.autoscroll();
- delay(8000);}
- else{
- digitalWrite(relay1, LOW);
- message=String("Turning off Cooling System as temp is *c :: ");
- message+=t;
- Serial.println(message);
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(message);
- lcd.autoscroll();
- delay(8000);}
- }
- //*******Code for GSM ********************************
- Blynk.run();
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t)) {
- Serial.println("Failed to read from DHT sensor!");
- }
- else{
- // You can delete the following Serial.print's, it's just for debugging purposes
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Blynk.virtualWrite(V1,t);
- Blynk.virtualWrite(V2,h);
- Blynk.virtualWrite(V3,abs(val));
- if(t>30) //set temperatur level for notification
- {
- Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Temperature Increased over limit");
- Blynk.notify("Temperature Increased over limit (> 35 *c");
- }
- if(h>60) //set Humid level for notification
- {
- Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Humidity Increased over limit");
- Blynk.notify("Humidity Increased over limit(> 70%)");
- }
- if(abs(val)<30) //set Moisture level for notification
- {
- Blynk.email("das.deepika300988@gmail.com", "ESP8266 Alert", "Humidity Increased over limit");
- Blynk.notify("Moisture Reduced to critical limit (< 30 %)");
- }
- }
- }
Add Comment
Please, Sign In to add comment