I need the relay switch on to make a water pump work when water touches float sensor, can you help me pls?
//////////////////////////////////////////BLYNK CONFIGURATION////////////////////////////////////////////////////////////////////////
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template setting
#define BLYNK_TEMPLATE_ID "****************"
#define BLYNK_TEMPLATE_NAME "*********************"
#define BLYNK_AUTH_TOKEN "**************************"
#define BLYNK_PRINT Serial // Enable debug prints
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
////////////////////////////////////////// WIFI CREDENTIALS ////////////////////////////////////////////////////////////////////////
// Your WiFi credentials.
// Set password to "" for open networks.
// Replace with your network credentials (STATION)
#define WiFiNumber 5
const char* ssid[] = {"SaigiWiFi", "TP-Link_1ED8", "DAP2553", "TP-Link_2210", "SAIGI", "SAIGI2"};
const char* pass[] = {"Casa.2017S", "06664732", "saigi123456", "59365891", "Zs2x7oAz", "Zs2x7oAz"};
////////////////////////////////////////// CONNECTIONS /////////////////////////////////////////////////////////////
#define RELAY_PIN 25 // Relay pin number
#define SENSOR_PIN 33 // Float sensor pin number
BlynkTimer timer;
unsigned long blynkTimer = 60000; // 60 seconds
bool relayState = false; // Store the current state of the relay
void setup()
{
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
pinMode(SENSOR_PIN, INPUT);
char auth[] = BLYNK_AUTH_TOKEN;
}
void loop()
{
float waterLevel = analogRead(SENSOR_PIN); // Read the water level from the sensor
waterLevel = map(waterLevel, 0, 4095, 0, 100); // Map the sensor reading to a percentage value
Serial.print("Water Level: ");
Serial.print(waterLevel);
Serial.println("%");
bool relayStateNew = (waterLevel > 50); // Determine the new state of the relay
if (relayStateNew != relayState) // If the new state is different than the current state
{
relayState = relayStateNew; // Update the current state of the relay
digitalWrite(RELAY_PIN, relayState ? HIGH : LOW); // Turn on or off the relay based on the new state
Serial.println(relayState ? "Relay ON" : "Relay OFF");
}
delay(1000); // Wait for 10 second before reading the water level sensor again
Blynk.run();
}