Techatronic
Published

Blynk IoT Smart farming using water pump

In this, you can control the water pump for watering the plants with the help of the Blynk application.

IntermediateProtip1 hour3,705
Blynk IoT Smart farming using water pump

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
 //TECHATRONIC.COM  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 #define BLYNK_PRINT Serial        
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <ESP8266mDNS.h>   
 #include <WiFiUdp.h>  
 #include <ArduinoOTA.h>   
 BlynkTimer timer;  
 void checkPhysicalButton();  
 int relay1State = LOW;  
 int pushButton1State = HIGH;  
 #define AUTH "P5weseHWDxxkwm-SH0GARQt9lStSl-hF"   
 #define WIFI_SSID "DESKTOP"  //Enter WIFI Name           
 #define WIFI_PASS "asdfghjkl" //Enter WIFI Password        
 #define SERVER "blynk-cloud.com "        
 #define PORT 8442  
 #define RELAY_PIN_1   D4  
 #define PUSH_BUTTON_1  D6  
 #define VPIN_BUTTON_1  V12   
 #define OTA_HOSTNAME "Home_Automation"  
 BLYNK_CONNECTED() {  
  // Request the latest state from the server  
  Blynk.syncVirtual(VPIN_BUTTON_1);  
 }  
 // When App button is pushed - switch the state  
 BLYNK_WRITE(VPIN_BUTTON_1) {  
  relay1State = param.asInt();  
  digitalWrite(RELAY_PIN_1, relay1State);  
 }  
 void checkPhysicalButton()  
 {  
  if (digitalRead(PUSH_BUTTON_1) == LOW) {  
   // pushButton1State is used to avoid sequential toggles  
   if (pushButton1State != LOW) {  
    // Toggle Relay state  
    relay1State = !relay1State;  
    digitalWrite(RELAY_PIN_1, relay1State);  
    // Update Button Widget  
    Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);  
   }  
   pushButton1State = LOW;  
  } else {  
   pushButton1State = HIGH;  
  }  
 }  
 void setup()  
 {  
  Serial.begin(115200);  
  Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS,"blynk-cloud.com", 8442);  
  ArduinoOTA.setHostname(OTA_HOSTNAME); // For OTA - Use your own device identifying name  
  ArduinoOTA.begin(); // For OTA  
  pinMode(RELAY_PIN_1, OUTPUT);  
  pinMode(PUSH_BUTTON_1, INPUT_PULLUP);  
  digitalWrite(RELAY_PIN_1, relay1State);  
  // Setup a function to be called every 100 ms  
  timer.setInterval(500L, checkPhysicalButton);  
 }  
 void loop()  
 {  
  Blynk.run();  
  ArduinoOTA.handle();   
  timer.run();  
 }  

Code snippet #2

Plain text
 //TECHATRONIC.COM  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 #define BLYNK_PRINT Serial        
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <ESP8266mDNS.h>   
 #include <WiFiUdp.h>  
 #include <ArduinoOTA.h>   
 BlynkTimer timer;  
 void checkPhysicalButton();  
 int relay1State = LOW;  
 int pushButton1State = HIGH;  
 #define AUTH "P5weseHWDxxkwm-SH0GARQt9lStSl-hF"   
 #define WIFI_SSID "DESKTOP"  //Enter WIFI Name           
 #define WIFI_PASS "asdfghjkl" //Enter WIFI Password        
 #define SERVER "blynk-cloud.com "        
 #define PORT 8442  
 #define RELAY_PIN_1   D4  
 #define PUSH_BUTTON_1  D6  
 #define VPIN_BUTTON_1  V12   
 #define OTA_HOSTNAME "Home_Automation"  
 BLYNK_CONNECTED() {  
  // Request the latest state from the server  
  Blynk.syncVirtual(VPIN_BUTTON_1);  
 }  
 // When App button is pushed - switch the state  
 BLYNK_WRITE(VPIN_BUTTON_1) {  
  relay1State = param.asInt();  
  digitalWrite(RELAY_PIN_1, relay1State);  
 }  
 void checkPhysicalButton()  
 {  
  if (digitalRead(PUSH_BUTTON_1) == LOW) {  
   // pushButton1State is used to avoid sequential toggles  
   if (pushButton1State != LOW) {  
    // Toggle Relay state  
    relay1State = !relay1State;  
    digitalWrite(RELAY_PIN_1, relay1State);  
    // Update Button Widget  
    Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);  
   }  
   pushButton1State = LOW;  
  } else {  
   pushButton1State = HIGH;  
  }  
 }  
 void setup()  
 {  
  Serial.begin(115200);  
  Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS,"blynk-cloud.com", 8442);  
  ArduinoOTA.setHostname(OTA_HOSTNAME); // For OTA - Use your own device identifying name  
  ArduinoOTA.begin(); // For OTA  
  pinMode(RELAY_PIN_1, OUTPUT);  
  pinMode(PUSH_BUTTON_1, INPUT_PULLUP);  
  digitalWrite(RELAY_PIN_1, relay1State);  
  // Setup a function to be called every 100 ms  
  timer.setInterval(500L, checkPhysicalButton);  
 }  
 void loop()  
 {  
  Blynk.run();  
  ArduinoOTA.handle();   
  timer.run();  
 }  

Github

https://github.com/ekstrand/ESP8266wifi

Github

https://github.com/blynkkk/blynk-library

Github

https://github.com/jandrassy/ArduinoOTA

Credits

Techatronic
72 projects • 127 followers
Electronic engineer

Comments