This circuit is designed to control a water pump and measure the flow of water using a flow sensor. The system is controlled by an Arduino 101 microcontroller, which interfaces with an ESP8266 NodeMCU for wireless communication. A 5V relay is used to control the water pump, and a 12V power supply provides the necessary power for the pump and other components. The system also includes a plastic solenoid valve to control the flow of water.
Arduino 101
Water Flow Sensor
Water Pump 12V
SparkFun Load Cell Amplifier - HX711
ESP8266 NodeMCU
Infrared Proximity Sensor
5V Relay
Power Supply 12V 5AMP
Plastic Solenoid Valve
12V Battery
12V Power Supply
#include <LiquidCrystal.h>
// Define LCD pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// Define flow sensor pin and relay pin
#define FLOW_SENSOR_PIN 2 // Interrupt pin for flow sensor
#define RELAY_PIN 8 // Pin to control the fuel pump relay
// Variables for flow sensor and calculations
volatile int flowPulseCount = 0; // Count pulses from the flow sensor
float flowRate = 0.0; // Flow rate in liters/minute
float fuelDispensed = 0.0; // Total fuel dispensed in liters
float pricePerLiter = 94.77; // Petrol price (in INR per liter)
float amountPaid = 100.0; // Amount paid by the customer (example)
float targetFuelVolume; // Fuel volume to dispense (calculated)
// ISR for flow sensor
void flowSensorISR() {
flowPulseCount++;
}
void setup() {
// Setup LCD
lcd.begin(16, 2);
lcd.print("Initializing...");
// Setup pins
pinMode(FLOW_SENSOR_PIN, INPUT_PULLUP); // Flow sensor
pinMode(RELAY_PIN, OUTPUT); // Relay control
digitalWrite(RELAY_PIN, LOW); // Start with pump off
// Attach interrupt for flow sensor
attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_PIN), flowSensorISR, RISING);
// Calculate target volume based on payment
targetFuelVolume = amountPaid / pricePerLiter;
// Display welcome message
lcd.clear();
lcd.print("Payment Recvd:");
lcd.setCursor(0, 1);
lcd.print("Rs ");
lcd.print(amountPaid);
delay(3000);
}
void loop() {
// Calculate flow rate and fuel dispensed
flowRate = (flowPulseCount / 450.0); // Adjust this factor based on flow sensor specs
fuelDispensed += flowRate / 60.0; // Convert flow rate to liters per second
// Display fuel dispensing progress
lcd.clear();
lcd.print("Dispensing...");
lcd.setCursor(0, 1);
lcd.print(fuelDispensed, 2); // Display up to 2 decimal places
lcd.print(" L");
// Start the pump if below target volume
if (fuelDispensed < targetFuelVolume) {
digitalWrite(RELAY_PIN, HIGH); // Turn on the pump
} else {
// Stop the pump and finish dispensing
digitalWrite(RELAY_PIN, LOW); // Turn off the pump
lcd.clear();
lcd.print("Dispense Done!");
lcd.setCursor(0, 1);
lcd.print("Thank You!");
while (true); // Stop execution
}
delay(1000); // Small delay for smooth operation
}
This code is designed to control the water pump based on the flow rate measured by the flow sensor. The Arduino 101 microcontroller reads the flow sensor data, calculates the flow rate, and controls the relay to turn the pump on or off. The LCD displays the amount of fuel dispensed and other relevant information.