Hi
I am new to Blynk and need help in working on a simple project which can operate a water pump using button in Blynk app.
I am trying to make the water pump to be controllable through two options where,
- manually control by pressing the first button.
- automatically pump the water based on the soil moisture sensor value having the second button to be activated (switch button) first.
While I have no problem working on the first option, however the second option is the one I am struggling with… I have tried to use IF ELSE statement so that the pump will operates when the soil moisture is at a specific level or else it will not. When I pressed the second button, the water pump will only process based on the first value that come up upon the button is activated.
Have the value of the moisture is at the ON level on the first time the button is pressed, the water pump will operates and does not turn off even though the moisture level has changed to OFF level. If the button is switched off and on again only then it will read the latest moisture level and turn off the water pump if the level is at OFF level.
What I am trying to achieve here in the program is that if the second button is switched on, the user can rely on the system to operate the water pump automatically based on the soil moisture level.
I am using Arduino UNO+ESP8266 as the WiFI shield and running the latest Blynk version through its app.
Any help on correction, suggestions and recommendation would be much appreciated. Thanks.
#define BLYNK_TEMPLATE_ID "TMPLBH_UJakl"
#define BLYNK_DEVICE_NAME "Water pump Test1"
#define BLYNK_AUTH_TOKEN "4MQeEtG41MXPU8Bejr0gf2n3oGwI3Jw8"
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h> //Uno-ESP Communication
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 38400 //ESP8266 baud rate:
ESP8266 wifi(&EspSerial);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "user";
char pass[] = "pass";
const int pump1 = 8;
// Button for (OPTION1)(MANUAL)
BLYNK_WRITE(V7){
if(param.asInt() == 1)
{
// Current Flowing (Relay)
digitalWrite(pump1,HIGH);
delay(3500); // 3.5 secs ~around 100ml
// Current Not Flowing (Relay)
digitalWrite(pump1,LOW);
delay(500); // 0.5 sec
}
}
// Button for (OPTION2)(AUTO)
BLYNK_WRITE(V6){
if(param.asInt() == 1)
{
int value = analogRead(A0);
value = map(value, 0, 1023, 0, 100);
Blynk.virtualWrite(V2, value);
if(value >=45 && value <=70){
// Current Flowing (Relay)
digitalWrite(pump1,HIGH);
}
else
{
// Current Not Flowing (Relay)
digitalWrite(pump1,LOW);
}
}
}
void setup() {
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(pump1, OUTPUT);
}
void loop() {
Blynk.run();
}