Hello, I’m working on a smart watering system project for school. The code below is totally alright but I’m facing a problem with Blynk. As you can see the code below, when the user presses the button V2 the watering will start and when he presses V2 again the watering will stop. But when trying this code on a prototype, it works as if there’s no button. I mean when the system is connected to buttery the watering doesn’t stop only when the water ends. Even the humidity level doesn’t work efficiently: it shows levels which are not compatible with the current humidity. What should I do? Help me please. Thank you.
#include <Simpletimer.h>
//Include the library files
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//Initialize the LCD display
char auth[] = "3h6ej_tnRtqKggWs6TG-YcUxmC44MDMA";//Enter your Auth token
char ssid[] = "ooredoo5CB565";//Enter your WIFI name
char pass[] = "ABE048C3Vh!50";//Enter your WIFI password
BlynkTimer timer;
bool Relay = 0;
//Define component pins
#define sensor 34
#define waterPump 26
void setup() {
Serial.begin(9600);
pinMode(waterPump, OUTPUT);
digitalWrite(waterPump, HIGH);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Call the function
timer.setInterval(1000L, soilMoistureSensor);
}
//Get the button value
BLYNK_WRITE(V2) {
Relay = param.asInt();
if (Relay == 1) {
digitalWrite(waterPump, LOW);
} else {
digitalWrite(waterPump, HIGH);
}
}
//Get the soil moisture values
void soilMoistureSensor() {
int value = analogRead(sensor);
value = map(value, 0, 1024, 0, 100);
value = (value - 100) * -1;
Blynk.virtualWrite(V1, value);
}
void loop() {
Blynk.run();//Run the Blynk library
timer.run();//Run the Blynk timer
}