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

Arduino-Controlled Automated Liquid Dispensing System with Weight Measurement

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Automated Liquid Dispensing System with Weight Measurement

Circuit Documentation

Summary

The circuit in question is designed to control a peristaltic pump and two micro servos using an Arduino UNO microcontroller. The system also includes a 5V relay to switch the pump, a 12V power supply for the pump, a 16x2 I2C LCD for display purposes, an HX711 bridge sensor interface for weight measurement, and a load cell as the weighing sensor. The Arduino UNO is programmed to operate the servos and pump based on the weight measurements from the load cell, providing a controlled dispensing system.

Component List

Arduino UNO

5V Relay

12V Power Supply

Micro Servo 9G (x2)

Peristaltic Pump

16x2 I2C LCD

HX711 - Bridge Sensor Interface

Load Cell - Red/white/black/green

Wiring Details

Arduino UNO

5V Relay

12V Power Supply

Micro Servo 9G

Peristaltic Pump

16x2 I2C LCD

HX711 - Bridge Sensor Interface

Load Cell - Red/white/black/green

Documented Code

#include <Servo.h>
#include <HX711.h>

// Pin assignments
int servoPin1 = 5;  // Red Valve
int servoPin2 = 6; // Blue Valve
const int pumpPin = 9;

// Servo objects
Servo servoRed;
Servo servoBlue;

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

HX711 scale;
float redWeight = 0;  // Desired weight for Red Liquid (grams)
float blueWeight = 0;  // Desired weight for Blue Liquid (grams)

// State tracking
bool redValveOpen = false;
bool blueValveOpen = false;

void setup() {
    // Attach servos to pins
    servoRed.attach(servoPin1);
    servoBlue.attach(servoPin2);

    // Initialize both servos to closed state (0 degrees)
    servoRed.write(0);
    servoBlue.write(0);

    // Initialize the scale
    Serial.begin(115200);
    scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

    // Tare the scale to zero out
    if (scale.is_ready()) {
        Serial.println("Taring... Remove any weights.");
        delay(5000);
        scale.tare();
        Serial.println("Tare done. Ready to measure.");
    } else {
        Serial.println("HX711 not found.");
    }

    // Set pump pin as output
    pinMode(pumpPin, OUTPUT);
    digitalWrite(pumpPin, LOW);  // Ensure pump is off initially
    inputWeights();
}

void loop() {
    // Open Red Valve until redWeight is reached
    float currentWeight = 0;  // Variable to hold the current weight

    // Open the Red Valve and start the pump
    if (!redValveOpen) {
        servoRed.write(90);  // Open the Red Valve
        digitalWrite(pumpPin, HIGH);  // Start the pump
        redValveOpen = true;
        Serial.println(F("Red Valve opened."));
    }

    // Continuously check the current weight
    while (currentWeight < redWeight) {
        currentWeight = scale.get_units(10);  // Measure the weight
        Serial.print(F("Current Weight: "));
        Serial.println(currentWeight);
        delay(100);  // Small delay to avoid overwhelming the processor
    }

    // Once the target weight is reached, close the Red Valve
    servoRed.write(0);  // Close the Red Valve
    digitalWrite(pumpPin, LOW);   // Stop the pump
    redValveOpen = false;  // Update the state
    Serial.println(F("Red Valve closed."));

    // Repeat for the Blue Valve
    // Open Blue Valve until blueWeight is reached
    currentWeight = 0;  // Reset current weight for the blue liquid

    // Open the Blue Valve and start the pump
    if (!blueValveOpen) {
        servoBlue.write(90);  // Open the Blue Valve
        digitalWrite(pumpPin, HIGH);  // Start the pump
        blueValveOpen = true;
        Serial.println(F("Blue Valve opened."));
    }

    // Continuously check the current weight for the blue liquid
    while (currentWeight < blueWeight) {
        currentWeight = scale.get_units(10);  // Measure the weight
        Serial.print(F("Current Weight: "));
        Serial.println(currentWeight);
        delay(100);  // Small delay to avoid overwhelming the processor
    }

    // Once the target weight is reached, close the Blue Valve
    servoBlue.write(0);  // Close the Blue Valve
    digitalWrite(pumpPin, LOW);   // Stop the pump
    blueValveOpen = false;  // Update the state
    Serial.println(F("Blue Valve closed."));

    // Add a delay or condition to avoid immediate repetition
    delay(1000);  // Wait before the next loop iteration (optional)
}

void inputWeights() {
    Serial.println("Enter desired weight for Red Liquid (grams): ");
    while (Serial.available() == 0);  // Wait for user input
    redWeight = Serial.parseFloat();   // Read the input and convert to float
    Serial.print("Red weight set to: ");
    Serial.println(redWeight);
    
    Serial.println("Enter desired weight for Blue Liquid (grams): ");
    while (Serial.available() == 0);  // Wait for user input