#define BLYNK_TEMPLATE_ID "Your_Template_ID"
#define BLYNK_DEVICE_NAME "Motor Pump Monitor"
#define BLYNK_AUTH_TOKEN "Your_Blynk_Auth_Token"
#include <WiFi.h>
// WiFi credentials
char ssid[] = "Wokwi-GUEST"; // Wokwi default WiFi
char pass[] = "";
// Pins
#define VOLTAGE_PIN 34 // Voltage sensor
#define CURRENT_PIN 35 // Current sensor (ACS712)
#define FLOW_PIN 27 // Water flow sensor
#define RELAY_PIN 26 // Motor pump control
// Flow variables
volatile int pulseCount;
float calibrationFactor = 4.5; // Adjust as per your flow sensor spec
unsigned long oldTime = 0;
// Blynk Timer
BlynkTimer timer;
// ISR for flow sensor
void IRAM_ATTR pulseCounter() {
pulseCount++;
}
// Read sensors and send to Blynk
void sendSensorData() {
// ----- Voltage -----
int adcValue = analogRead(VOLTAGE_PIN);
float voltage = (adcValue / 4095.0) * 3.3 * (11.0); // assuming divider ratio 11:1
Blynk.virtualWrite(V1, voltage);
// ----- Current -----
int adcCurrent = analogRead(CURRENT_PIN);
float voltageCurrent = (adcCurrent / 4095.0) * 3.3;
float current = (voltageCurrent - 2.5) / 0.185; // ACS712 5A module
Blynk.virtualWrite(V2, current);
// ----- Flow -----
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - oldTime;
float flowRate = ((1000.0 / elapsedTime) * pulseCount) / calibrationFactor;
oldTime = currentTime;
pulseCount = 0;
Blynk.virtualWrite(V3, flowRate);
// Debug
Serial.print("Voltage: "); Serial.print(voltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current); Serial.println(" A");
Serial.print("Flow Rate: "); Serial.print(flowRate); Serial.println(" L/min");
}
// Blynk control for motor pump
BLYNK_WRITE(V4) {
int state = param.asInt();
digitalWrite(RELAY_PIN, state);
Serial.print("Pump State: ");
Serial.println(state ? "ON" : "OFF");
}
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
pinMode(FLOW_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(FLOW_PIN), pulseCounter, FALLING);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(2000L, sendSensorData);
}
void loop() {
Blynk.run();
timer.run();
}