Tuesday, June 25, 2019

Week 8: FYP2 The fully prototype


This is complete prototype of Development of an Intelligent Solar Powered Watering System. And i will show complete coding for this program.


// include your ESP library here
// and other blynk widget
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>                                        
#include <SPI.h>
#include <DHT.h>

// Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "554d6e1520e64e33b8924af9eb66423d";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Adam Jasman";
char pass[] = "qwertyuiop";

#define DHTPIN 5     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)


DHT dht(DHTPIN, DHTTYPE);
int sensorData;
int threshold;
SimpleTimer timer; // allocate a name (mytimer) to the timer
int selectmode; //Select Mode for Auto or Manual
int button2; //Manual Blynk Case 1 ONOFF
int timer2; //Manual Blynk
int timer3; //Auto Blynk
int val; //sensor
int morning;
int night;

//Configuration of the widges used at the Blynk panel in the mobile
WidgetLED led1(V1); //virtual led Blynk for Motor 1
WidgetLED led4(V7); //virtual led Blynk for Auto Mode
WidgetLED led5(V8); //virtual led Blynk for Manual Mode
WidgetLED led6(V0); //virtual led Blynk for sensor 1


void setup()
{
Serial.begin(115200);     // Set ESP8266 baud rate
Blynk.begin(auth, ssid, pass); // Here your Arduino connects to the Blynk Cloud.
//declare sensor dht
pinMode(5,INPUT);
//Motor
pinMode(14,OUTPUT); 
//Sensor
pinMode(A0,INPUT);
dht.begin();
}

void loop()

{
 
// 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();
// Read temperature as Celsius
float t = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
  }

Blynk.virtualWrite(V0,t);
Blynk.virtualWrite(V3,h);
Blynk.run(); // Initiates Blynk
timer.run(); // call the simple timer routine

}

void Timer()

{
if(night||morning==1 && selectmode==0)
{
Auto();
Blynk.email("adam.sumax@gmail.com", "Subject: Plant Watering System", "Adam watering ur plant...");
Blynk.notify("automation watering alert - Siram");
}
}

void Auto()

{
val = analogRead(A0);
if(val<threshold) //if sensor 1 high
{
digitalWrite(14,LOW); 
led1.on(); // led Motor 1 blynk on
led6.off(); // led Sensor 1 blynk on
  }
  else
  {
digitalWrite(14,HIGH); 
led1.off(); // Led Motor 1 blynk off
led6.on(); // led Sensor 1 blynk off
  }

  }

void Manual()
{
if(button2==1&&selectmode==1)
{
digitalWrite(14,LOW);//Motor 1 On 
led1.on(); // light 1 blynk on
    }
 else
 {
  digitalWrite(14,HIGH);//Motor 1 Off 
  led1.off(); // light 1 blynk off

  }
 
}

BLYNK_WRITE(V2){   // add a slider to your project on V0 range 0 to 30 (minutes)
  threshold = param.asInt();  // set variable as Slider value
}

BLYNK_WRITE(V5)
{
  // You'll get HIGH/1 at startTime and LOW/0 at stopTime.
  // this method will be triggered every day
  // until you remove widget or stop project or
  // clean stop/start fields of widget
night = param.asInt();
}

BLYNK_WRITE(V9) // Case 1 ONOFF
{
 button2 = param.asInt(); // Get the state of the VButton for Case 1 ONOFF
}

// Sets btnPin HIGH or LOW depending on state of Button Widget
BLYNK_WRITE(V6) //Select Mode
{
selectmode = param.asInt(); // Get the state of the VButton for selectmode
if(selectmode ==1){
timer.disable(timer3); // Disables the timer3
    led5.on(); // light 5 blynk on
    led4.off(); // light 4 blynk off
timer2=timer.setInterval(1000L, Manual);   // Setup a function to be called every 1000 ms
 }
 else
{
timer.disable(timer2); //Disables the timer2
   led4.on(); // light 4 blynk on
   led5.off(); // light 5 blynk off
  timer3=timer.setInterval(1500, Timer); // Setup a function to be called every 1500 ms
 }
}

BLYNK_CONNECTED()
{
Blynk.syncVirtual(V6); //Select Mode
Blynk.syncVirtual(V9); // Case 1 ONOFF
Blynk.syncVirtual(V5); //Select Mode
Blynk.syncVirtual(V10); // Case 1 ONOFF 
Blynk.syncVirtual(V6); //Select Mode
Blynk.syncVirtual(V2); // Case 1 ONOFF

No comments:

Post a Comment