Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • GND: Connected to GND of 5V relay, ESP8266 NodeMCU, water flow sensor, and common terminal of 5V relay.
  • D8: Connected to In pin of 5V relay.
  • D2: Connected to Signal pin of water flow sensor.
  • D1/TX: Connected to RX pin of ESP8266 NodeMCU.
  • D0/RX: Connected to TX pin of ESP8266 NodeMCU.
  • 3V3: Connected to VIN pin of ESP8266 NodeMCU.
  • 5V: Connected to VCC pin of 5V relay and Vcc pin of water flow sensor.

Water Flow Sensor

  • Signal: Connected to D2 pin of Arduino 101.
  • Vcc: Connected to 5V pin of Arduino 101.
  • GND: Connected to GND pin of Arduino 101.

Water Pump 12V

  • +: Connected to Normally Open pin of 5V relay.
  • -: Connected to 12V-24V Output (DC) pin of Power Supply 12V 5AMP.

SparkFun Load Cell Amplifier - HX711

  • Not connected in this circuit.

ESP8266 NodeMCU

  • GND: Connected to GND pin of Arduino 101.
  • RX: Connected to D1/TX pin of Arduino 101.
  • TX: Connected to D0/RX pin of Arduino 101.
  • VIN: Connected to 3V3 pin of Arduino 101.

Infrared Proximity Sensor

  • Not connected in this circuit.

5V Relay

  • GND: Connected to GND pin of Arduino 101.
  • In: Connected to D8 pin of Arduino 101.
  • VCC: Connected to 5V pin of Arduino 101.
  • Common terminal: Connected to GND pin of Arduino 101 and GND pin of Power Supply 12V 5AMP.
  • Normally Open: Connected to + pin of Water Pump 12V.
  • Normally Closed: Connected to pin1 of Plastic Solenoid Valve.

Power Supply 12V 5AMP

  • GND: Connected to Common terminal pin of 5V relay.
  • 12V-24V Output (DC): Connected to - pin of Water Pump 12V and pin2 of Plastic Solenoid Valve.

Plastic Solenoid Valve

  • pin1: Connected to Normally Closed pin of 5V relay.
  • pin2: Connected to 12V-24V Output (DC) pin of Power Supply 12V 5AMP.

12V Battery

  • Not connected in this circuit.

12V Power Supply

  • Not connected in this circuit.

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.