// =====================================================
// AGRICULTURAL PUMP ENERGY MANAGEMENT SYSTEM
// ESP32 - WOKWI
// NO EXTERNAL LIBRARIES
// =====================================================
#define CURRENT_PIN 34
#define TEMP_PIN 35
#define VIBRATION_PIN 27
#define PUMP_RELAY 25
#define FAULT_LED 26
// ---------------- LIMITS ----------------
#define CURRENT_WARNING 2.0
#define CURRENT_TRIP 3.0
#define TEMP_WARNING 50.0
#define TEMP_TRIP 60.0
// Pump voltage for prototype
#define PUMP_VOLTAGE 12.0
// ---------------- ENERGY ----------------
float energyWh = 0.0;
unsigned long previousTime;
// =====================================================
// SETUP
// =====================================================
void setup()
{
Serial.begin(115200);
pinMode(CURRENT_PIN, INPUT);
pinMode(TEMP_PIN, INPUT);
pinMode(VIBRATION_PIN, INPUT_PULLUP);
pinMode(PUMP_RELAY, OUTPUT);
pinMode(FAULT_LED, OUTPUT);
// Start pump automatically
digitalWrite(PUMP_RELAY, HIGH);
digitalWrite(FAULT_LED, LOW);
previousTime = millis();
Serial.println();
Serial.println("======================================");
Serial.println(" AGRICULTURAL PUMP MONITOR");
Serial.println("======================================");
Serial.println("Pump Started");
}
// =====================================================
// LOOP
// =====================================================
void loop()
{
// ---------------------------------------------------
// CURRENT
// ---------------------------------------------------
int currentADC = analogRead(CURRENT_PIN);
float current =
(currentADC / 4095.0) * 5.0;
// ---------------------------------------------------
// TEMPERATURE
// ---------------------------------------------------
int temperatureADC = analogRead(TEMP_PIN);
float temperature =
20.0 + (temperatureADC / 4095.0) * 60.0;
// ---------------------------------------------------
// VIBRATION
// ---------------------------------------------------
bool vibration =
digitalRead(VIBRATION_PIN) == LOW;
// ---------------------------------------------------
// FAULTS
// ---------------------------------------------------
bool overCurrent =
current > CURRENT_TRIP;
bool overTemperature =
temperature > TEMP_TRIP;
// ---------------------------------------------------
// PUMP CONTROL
// ---------------------------------------------------
bool pumpON = true;
// Critical faults stop the pump
if (overCurrent || overTemperature)
{
pumpON = false;
}
// ---------------------------------------------------
// RELAY
// ---------------------------------------------------
if (pumpON)
{
digitalWrite(PUMP_RELAY, HIGH);
}
else
{
digitalWrite(PUMP_RELAY, LOW);
}
// ---------------------------------------------------
// FAULT LED
// ---------------------------------------------------
if (overCurrent || overTemperature)
{
digitalWrite(FAULT_LED, HIGH);
}
else
{
digitalWrite(FAULT_LED, LOW);
}
// ---------------------------------------------------
// POWER
// ---------------------------------------------------
float power = PUMP_VOLTAGE * current;
// ---------------------------------------------------
// ENERGY
// ---------------------------------------------------
unsigned long currentTime = millis();
float elapsedHours =
(currentTime - previousTime) / 3600000.0;
previousTime = currentTime;
if (pumpON)
{
energyWh += power * elapsedHours;
}
// ---------------------------------------------------
// SERIAL MONITOR
// ---------------------------------------------------
Serial.println();
Serial.println("--------------------------------------");
Serial.print("Current : ");
Serial.print(current, 2);
Serial.println(" A");
Serial.print("Temperature : ");
Serial.print(temperature, 1);
Serial.println(" C");
Serial.print("Vibration : ");
if (vibration)
Serial.println("DETECTED");
else
Serial.println("NORMAL");
Serial.print("Power : ");
Serial.print(power, 2);
Serial.println(" W");
Serial.print("Energy : ");
Serial.print(energyWh, 4);
Serial.println(" Wh");
Serial.print("Pump : ");
if (pumpON)
Serial.println("ON");
else
Serial.println("OFF");
// ---------------------------------------------------
// STATUS
// ---------------------------------------------------
if (overCurrent)
{
Serial.println();
Serial.println("CRITICAL: OVERCURRENT");
Serial.println("RELAY: PUMP OFF");
}
else if (overTemperature)
{
Serial.println();
Serial.println("CRITICAL: OVER TEMPERATURE");
Serial.println("RELAY: PUMP OFF");
}
else if (current > CURRENT_WARNING ||
temperature > TEMP_WARNING ||
vibration)
{
Serial.println();
Serial.println("STATUS: MAINTENANCE REQUIRED");
}
else
{
Serial.println();
Serial.println("STATUS: NORMAL OPERATION");
}
Serial.println("--------------------------------------");
delay(1000);
}Loading
mfrc522
mfrc522