#include <Arduino.h>
#include <ACS712.h> // Current sensor library
#include <INA219.h> // Voltage sensor library
#include <LiquidCrystal_I2C.h> // LCD display library (if used)
#define WATER_LEVEL_PIN A0 // Analog pin for water level sensor
#define PUMP_TEMPERATURE_PIN A1 // Analog pin for pump temperature sensor
#define RAIN_SENSOR_PIN 2 // Digital pin for rain sensor
#define RELAY1_PIN 13 // Digital pin for contactor relay 1
#define RELAY2_PIN 12 // Digital pin for contactor relay 2
#define RELAY3_PIN 11 // Digital pin for contactor relay 3
#define USER_SWITCH1_PIN 10 // Digital pin for user input switch 1
#define USER_SWITCH2_PIN 9 // Digital pin for user input switch 2
#define USER_SWITCH3_PIN 8 // Digital pin for user input switch 3
// Initialize ACS712 current sensors
ACS712 currentSensor1(A2);
ACS712 currentSensor2(A3);
ACS712 currentSensor3(A4);
// Initialize INA219 voltage sensors
INA219 voltageSensor1(5, 4);
INA219 voltageSensor2(3, 2);
INA219 voltageSensor3(1, 0);
// Initialize LCD display (if used)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define variables for sensor readings and system parameters
float waterLevel;
float pumpTemperature;
bool isRaining;
float current1, current2, current3;
float voltage1, voltage2, voltage3;
// Define system mode variables
enum SystemMode {
MANUAL,
AUTOMATIC
};
SystemMode systemMode = AUTOMATIC;
// Initialize user input switch states
bool userSwitch1State = false;
bool userSwitch2State = false;
bool userSwitch3State = false;
void setup() {
// Set serial communication for debugging
Serial.begin(115200);
// Initialize contactor relay pins as outputs
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(RELAY3_PIN, OUTPUT);
// Initialize user input switch pins as inputs
pinMode(USER_SWITCH1_PIN, INPUT_PULLUP);
pinMode(USER_SWITCH2_PIN, INPUT_PULLUP);
pinMode(USER_SWITCH3_PIN, INPUT_PULLUP);
// Initialize LCD display (if used)
lcd.init();
lcd.backlight();
lcd.print("Water Pump System");
}
void loop() {
// Read sensor data
readSensorData();
// Process sensor data and determine system status
processSensorData();
// Control contactor relays based on system mode and sensor data
controlContactorRelays();
// Handle user input switches
handleUserInputSwitches();
// Update LCD display (if used)
updateLCDDisplay();
// Delay for next loop iteration
delay(1000);
}
void readSensorData() {
// Read water level sensor
waterLevel = analogRead(WATER_LEVEL_PIN);
// Read pump temperature sensor
pumpTemperature = analogRead(PUMP_TEMPERATURE_PIN);
// Read rain sensor
isRaining = digitalRead(RAIN_SENSOR_PIN) == LOW;
// Read current sensors
current1 = currentSensor1.getCurrentACRMS();
current2 = currentSensor2.getCurrentACRMS();
current3 = currentSensor3.getCurrentACRMS();
// Read voltage sensors
voltage1 = voltageSensor1.getBusVoltage_V() / 1000.0;
voltage2 = voltageSensor2.getBusVoltage_V() / 1000.0;
voltage3 = voltageSensor3.getBusVoltage_V() / 1000.0;
}
void processSensorData() {
// Implement control logic based on sensor data and mode selection
// (automated or manual)
}
void controlContactorRelays() {
//