Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino and ESP8266-Based Automated Fuel Dispensing System with Flow Sensor and Relay Control

View and Edit Project In Cirkit DesignerImage of Arduino and ESP8266-Based Automated Fuel Dispensing System with Flow Sensor and Relay Control

Circuit Documentation

Summary

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.

Component List

  1. Arduino 101

    • Description: Microcontroller board based on the Intel Curie module.
    • Pins: A5/SCL, A4/SDA, AREF, GND, D13/SCK, D12/MISO, D11 PWM/MOSI, D10 PWM/SS, D9 PWM, D8, D7, D6 PWM, D5 PWM, D4, D3 PWM, D2, D1/TX, D0/RX, AIN, ioref, RESET, 3V3, 5V, VIN, A0, A1, A2, A3, ICSP MISO, ICSP SCK, ICSP MOSI
  2. Water Flow Sensor

    • Description: Sensor to measure the flow rate of water.
    • Pins: Signal, Vcc, GND
  3. Water Pump 12V

    • Description: 12V water pump.
    • Pins: +, -
  4. SparkFun Load Cell Amplifier - HX711

    • Description: Amplifier for load cell sensors.
    • Pins: VDD, VCC, DAT, SCK, GND, B+, B-, A+, A-, AVDD
  5. ESP8266 NodeMCU

    • Description: Wi-Fi module for wireless communication.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  6. Infrared Proximity Sensor

    • Description: Sensor to detect proximity using infrared light.
    • Pins: Vout, GND, Vcc
  7. 5V Relay

    • Description: Relay module to control high voltage devices.
    • Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
  8. Power Supply 12V 5AMP

    • Description: Power supply providing 12V DC at 5A.
    • Pins: 220V Positive Pole (AC), 220V Negative Pole (AC), GND, GND (DC), 12V-24V Output (DC)
  9. Plastic Solenoid Valve

    • Description: Valve to control the flow of water.
    • Pins: pin1, pin2
  10. 12V Battery

    • Description: 12V battery for power supply.
    • Pins: VCC, GND
  11. 12V Power Supply

    • Description: Power supply providing 12V DC.
    • Pins: +, -

Wiring Details

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

Documented Code

#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.