Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Wi-Fi Controlled Water Management System with Flow Sensors and Solenoid Valves

View and Edit Project In Cirkit DesignerImage of ESP32-Based Wi-Fi Controlled Water Management System with Flow Sensors and Solenoid Valves

Circuit Documentation

Summary

This circuit is a water management system that uses an ESP32 microcontroller to monitor water flow through three different sensors and control three solenoid valves via a relay module. The system is connected to the Blynk platform for remote monitoring and control. The circuit includes the following components:

Component List

ESP32

Water Flow Sensor (3 units)

Plastic Solenoid Valve (3 units)

Relay 4 Channel 5v

DC Power Source

Wiring Details

ESP32

Water Flow Sensor 1

Water Flow Sensor 2

Water Flow Sensor 3

Plastic Solenoid Valve 1

Plastic Solenoid Valve 2

Plastic Solenoid Valve 3

Relay 4 Channel 5v

DC Power Source

Code Documentation

#define BLYNK_TEMPLATE_ID "TMPL6-k4Y4yi4"  // Template ID
#define BLYNK_TEMPLATE_NAME "Water Management System"  // Template Name

#define BLYNK_AUTH_TOKEN "53WZtIU0niLoFvGOzzkslbL0tceD3lu7"

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Wi-Fi credentials
const char *ssid = "Hello 2";             // Wi-Fi SSID
const char *password = "A245618A245872";  // Wi-Fi Password
char auth[] = "53WZtIU0niLoFvGOzzkslbL0tceD3lu7";  // Blynk Auth Token

// Flow Sensor Pins
const int mainFlowSensorPin = 34;  // GPIO for main flow sensor
const int user1FlowSensorPin = 35; // GPIO for user 1 flow sensor
const int user2FlowSensorPin = 32; // GPIO for user 2 flow sensor

// Relay Pins (for solenoids)
const int mainRelayPin = 26;  // Relay for main flow sensor
const int user1RelayPin = 27; // Relay for user 1 flow sensor
const int user2RelayPin = 14; // Relay for user 2 flow sensor

// Variables to store flow sensor counts
volatile int mainFlowCount = 0;
volatile int user1FlowCount = 0;
volatile int user2FlowCount = 0;

// Flow rates in liters per minute
float mainFlowRate = 0;
float user1FlowRate = 0;
float user2FlowRate = 0;

// Flag to indicate leak
bool leakDetected = false;

// Pulse counters for calculating flow rate
void IRAM_ATTR countMainFlow() { mainFlowCount++; }
void IRAM_ATTR countUser1Flow() { user1FlowCount++; }
void IRAM_ATTR countUser2Flow() { user2FlowCount++; }

// Blynk virtual pins to control relays
BLYNK_WRITE(V1) {
  int state = param.asInt();
  if (state == 1) {
    digitalWrite(mainRelayPin, LOW);  // Relay ON (active LOW)
    Serial.println("Main solenoid opened (Relay ON)");
  } else {
    digitalWrite(mainRelayPin, HIGH); // Relay OFF (active LOW)
    Serial.println("Main solenoid closed (Relay OFF)");
  }
}

BLYNK_WRITE(V2) {
  int state = param.asInt();
  if (state == 1) {
    digitalWrite(user1RelayPin, LOW);  // Relay ON (active LOW)
    Serial.println("User 1 solenoid opened (Relay ON)");
  } else {
    digitalWrite(user1RelayPin, HIGH); // Relay OFF (active LOW)
    Serial.println("User 1 solenoid closed (Relay OFF)");
  }
}

BLYNK_WRITE(V3) {
  int state = param.asInt();
  if (state == 1) {
    digitalWrite(user2RelayPin, LOW);  // Relay ON (active LOW)
    Serial.println("User 2 solenoid opened (Relay ON)");
  } else {
    digitalWrite(user2RelayPin, HIGH); // Relay OFF (active LOW)
    Serial.println("User 2 solenoid closed (Relay OFF)");
  }
}

void setup() {
  Serial.begin(115200);

  // Initialize flow sensor pins
  pinMode(mainFlowSensorPin, INPUT_PULLUP);
  pinMode(user1FlowSensorPin, INPUT_PULLUP);
  pinMode(user2FlowSensorPin, INPUT_PULLUP);

  // Initialize relay pins
  pinMode(mainRelayPin, OUTPUT);
  pinMode(user1RelayPin, OUTPUT);
  pinMode(user2RelayPin, OUTPUT);

  // Set relays to OFF initially (solenoids closed)
  digitalWrite(mainRelayPin, HIGH);  // Active LOW