#define BLYNK_TEMPLATE_ID "TMPL2L1JAtM3R" // Define the Blynk template ID #define BLYNK_TEMPLATE_NAME "ESP32 FINAL PROJECT" // Define the Blynk template name #define BLYNK_AUTH_TOKEN "vbwqd0jSgHx8SR12pEOhHkTO03UNKGyk" // Define the Blynk authentication token /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial // Enable Serial output for debugging #include // Include the WiFi library for ESP32 #include // Include the Blynk library for ESP32 #include // Include the flow sensor library // Your WiFi credentials char ssid[] = "Depa703"; // SSID where I made my project char pass[] = "borgono10000"; // Password of the wifi network // Flow sensor setup FlowSensor Sensor(150, 8); // Create a flow sensor object with specific parameters const int solenoidPinUP = 4; // Pin connected to the UP solenoid valve const int solenoidPinUNDER = 2; // Pin connected to the UNDER solenoid valve const int mosfetPinPump = 3; // Pin connected to the MOSFET for the pump // Variables to control the solenoids and the pump from Blynk bool solenoidUPState = false; // Initial state of the UP solenoid valve bool solenoidUNDERState = false; // Initial state of the UNDER solenoid valve bool pumpState = true; // Turn on the pump by default void count() { Sensor.count(); // Increment the flow sensor counter } void setup() { // Debug console Serial.begin(115200); // Initialize the Serial communication at 115200 baud rate // Connect to Blynk Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // Connect to Blynk using the authentication token and WiFi credentials // Initialize the flow sensor Sensor.begin(count); // Initialize the flow sensor with the count function // Set the pins as outputs and activate them pinMode(solenoidPinUP, OUTPUT); // Set the UP solenoid pin as an output pinMode(solenoidPinUNDER, OUTPUT); // Set the UNDER solenoid pin as an output pinMode(mosfetPinPump, OUTPUT); // Set the MOSFET pump pin as an output // Turn on the pump at the start digitalWrite(mosfetPinPump, HIGH); // Turn on the pump by setting the pin HIGH } // Blynk functions to handle the solenoid and pump switches BLYNK_WRITE(V0) { solenoidUPState = param.asInt(); // Get the value from the Blynk app for the UP solenoid digitalWrite(solenoidPinUP, solenoidUPState); // Set the UP solenoid state Blynk.virtualWrite(V0, solenoidUPState); // Update the switch state in the Blynk dashboard } BLYNK_WRITE(V2) { solenoidUNDERState = param.asInt(); // Get the value from the Blynk app for the UNDER solenoid digitalWrite(solenoidPinUNDER, solenoidUNDERState); // Set the UNDER solenoid state Blynk.virtualWrite(V2, solenoidUNDERState); // Update the switch state in the Blynk dashboard } BLYNK_WRITE(V3) { pumpState = param.asInt(); // Get the value from the Blynk app for the pump digitalWrite(mosfetPinPump, pumpState); // Set the pump state Blynk.virtualWrite(V3, pumpState); // Update the switch state in the Blynk dashboard } void loop() { Blynk.run(); // Run the Blynk main loop }