hey, im trying to connect my esp to a 4 way relay with 4 pumps attached and have certain times of day that the pumps work for an amount of time i can change, each pump should have a different value. ive gotten the esp to connect and ive setup the time widgets using the mobile app but when the time comes the esp dosent trigger the relay at all. any help would be appreciated.
#define BLYNK_TEMPLATE_NAME "Irrigation system "
#define BLYNK_AUTH_TOKEN "*********"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// Replace with your network credentials
const char* ssid = "2test";
const char* password = "PJK9?jjDrS$4c5zF";
// Replace with your Blynk authentication token
const char* auth = "VrQ4_SpgJLYlnvnkfrS3ZTCV7yKtHw_U";
// Pin assignments for relay control
const int relayPins[] = {5, 6, 7, 8}; // Change these pins according to your setup
// Pump status variables
bool pumpStatus[] = {false, false, false, false}; // Keep track of pump status (ON/OFF)
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Connect to Blynk server
Blynk.begin(auth, ssid, password);
Serial.println("Connected to Blynk server");
// Initialize relay pins
for (int i = 0; i < sizeof(relayPins) / sizeof(relayPins[0]); i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], LOW);
}
}
void loop() {
Blynk.run();
}
// Blynk virtual pin handlers
BLYNK_WRITE(V0) {
int pumpIndex = param.asInt();
if (pumpIndex >= 0 && pumpIndex < sizeof(relayPins) / sizeof(relayPins[0])) {
pumpStatus[pumpIndex] = !pumpStatus[pumpIndex];
digitalWrite(relayPins[pumpIndex], pumpStatus[pumpIndex] ? HIGH : LOW);
}
}