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

Arduino-Controlled Liquid Level Management System with Overflow Protection

Image of Arduino-Controlled Liquid Level Management System with Overflow Protection

Circuit Documentation

Summary

This circuit is designed to control a water level system using various sensors, actuators, and an Arduino UNO microcontroller. The system includes red and green LEDs for status indication, a servo motor for mechanical control, a buzzer for audio alerts, pushbuttons for user input, non-contact water level sensors for detecting water levels, relays for controlling power to the servo and a solenoid valve, and a power supply to provide the necessary voltage for the components.

Component List

LED: Two Pin (red)

  • A red LED used for status indication.

LED: Two Pin (green)

  • A green LED used for status indication.

Arduino UNO

  • A microcontroller board based on the ATmega328P, used as the central controller for the circuit.

Servo

  • A servo motor used for precise control of mechanical movement.

1-Channel Relay (5V 10A)

  • An electromechanical switch used for controlling high power devices.

Power Supply

  • Provides the required voltage and current to power the circuit.

Pushbutton

  • A momentary switch used for user input.

Non-contact Water Level Sensor

  • A sensor used to detect the presence of water without direct contact.

Resistor (1000 Ohms)

  • A resistor with a resistance of 1000 Ohms, used for current limiting and voltage division.

Buzzer

  • An audio signaling device used for alerts.

12v Pneumatic Solenoid Valve

  • A valve controlled by an electric current through a solenoid, used for controlling the flow of air or liquid.

Wiring Details

LED: Two Pin (red)

  • Cathode connected to ground.
  • Anode connected to a 1000 Ohm resistor.

LED: Two Pin (green)

  • Cathode connected to ground.
  • Anode connected to a 1000 Ohm resistor.

Arduino UNO

  • GND pin connected to the common ground.
  • 5V pin provides power to various components.
  • Digital pins D2, D3, D5, D6, D7, D10, D12, and D13 are connected to sensors, relays, LEDs, and the buzzer.

Servo

  • GND pin connected to ground.
  • VCC pin connected to the Normally Open (NO) contact of a relay.
  • Pulse pin connected to the D10 pin on the Arduino UNO.

1-Channel Relay (5V 10A)

  • Ground pin connected to the common ground.
  • Power pin connected to the 5V supply from the Arduino UNO.
  • Signal pin connected to digital pins D5 and D7 on the Arduino UNO for control.
  • Common (C) and Normally Open (NO) contacts used for switching the servo and solenoid valve.

Power Supply

  • "+" pin connected to the Common (C) contact of a relay.
  • "-" pin connected to the ground.

Pushbutton

  • One side connected to the 5V supply.
  • The other side connected to a 1000 Ohm resistor.

Non-contact Water Level Sensor

  • VCC pin connected to the 5V supply.
  • GND pin connected to the common ground.
  • SIG pin connected to digital pins D2 and D3 on the Arduino UNO.

Resistor (1000 Ohms)

  • Used for current limiting for LEDs and debouncing for the pushbutton.

Buzzer

  • PIN connected to the D6 pin on the Arduino UNO.
  • GND connected to a 1000 Ohm resistor.

12v Pneumatic Solenoid Valve

  • VCC pin connected to the Normally Closed (NC) contact of a relay.
  • GND pin connected to the "-" pin of the power supply.

Documented Code

#include <Servo.h>

#define Liquid_Detection_Pin 2     // Output pin on liquid detection sensor
#define Overflow_Sensor_Pin 3      // Output pin on overflow sensor
#define Buzzer_Pin 6               // Pin for piezo buzzer
#define Servo_Pin 10               // Pin for servo motor
#define Start_Button_Pin 8         // Pin for start/stop button
#define Red_LED_Pin 13             // Pin for red LED (buzzer indicator)
#define Green_LED_Pin 12           // Pin for green LED (liquid detection indicator)
#define Solenoid_Pin 5             // Pin for solenoid relay
#define Motor_Relay_Pin 7          // Pin for motor relay

Servo myServo;  // Create a servo object
bool systemEnabled = false;  // Flag to indicate system status
bool buttonState = false;  // Flag to keep track of button state
unsigned long motorTimer = 0;  // Timer for motor run time
bool motorRunning = false;  // Flag to indicate motor running
bool waterDetected = false;  // Flag to indicate water detection
bool overflowDetected = false;  // Flag to indicate overflow detection

void setup() {
  Serial.begin(9600);
  pinMode(Liquid_Detection_Pin, INPUT);
  pinMode(Overflow_Sensor_Pin, INPUT);  // Initialize overflow sensor pin
  pinMode(Buzzer_Pin, OUTPUT);  // Set buzzer pin as output
  pinMode(Start_Button_Pin, INPUT_PULLUP);  // Use internal pull-up resistor
  pinMode(Red_LED_Pin, OUTPUT);  // Set red LED pin as output
  pinMode(Green_LED_Pin, OUTPUT);  // Set green LED pin as output
  pinMode(Solenoid_Pin, OUTPUT);  // Set solenoid relay pin as output
  pinMode(Motor_Relay_Pin, OUTPUT);  // Set motor relay pin as output
  myServo.attach(Servo_Pin);  // Attach the servo to the pin
  myServo.write(0);  // Initialize the servo to 0 degrees
}

void buzz() {
  tone(Buzzer_Pin, 1000, 200);  // Produce a 1 kHz tone for 200 ms
}

void buzzForOneSecond() {
  tone(Buzzer_Pin, 1000, 1000);  // Produce a 1 kHz tone for 1 second
}

void shutdownSystem() {
  // Turn off everything
  digitalWrite(Solenoid_Pin, LOW);  // Turn off solenoid relay
  digitalWrite(Motor_Relay_Pin, LOW);  // Turn off motor relay
  digitalWrite(Green_LED_Pin, LOW);  // Turn off green LED
  myServo.write(0);  // Stop the servo motor

  if (motorRunning) {
    motorRunning = false;  // Set motor running flag to false
  }

  systemEnabled = false;  // Disable the system
  waterDetected = false;  // Reset water detection flag
  overflowDetected = true;  // Mark the system as having overflowed

  Serial.println("System Shutdown Triggered.");
  
  // Buzzer beeps for 1 second and Red LED blinks for 5 seconds
  for (int i = 0; i < 5; i++) {
    digitalWrite(Red_LED_Pin, HIGH);  // Turn on red LED
    buzzForOneSecond();  // Beep the buzzer for 1 second
    delay(1000);  // Wait for 1 second
    digitalWrite(Red_LED_Pin, LOW);  // Turn off red LED
    delay(1000);  // Wait for 1 second
  }
}

void systemStartup() {
  // Blink green LED and sound buzzer for system startup
  for (int i = 0; i < 6; i++) {  // Blink for 3 seconds (500ms on/off cycle)
    digitalWrite(Green_LED_Pin, HIGH);  // Turn on green LED
    buzz();  // Buzz for 200ms
    delay(500);  // Wait 500ms
    digitalWrite(Green_LED_Pin, LOW);  // Turn off green LED
    delay(500);  // Wait 500ms
  }
}

void loop() {
  int currentState = digitalRead(Start_Button_Pin);
  int overflowState = digitalRead(Overflow_Sensor_Pin);  // Read overflow sensor state
  
  if (overflowState == LOW) {  // Overflow sensor triggered
    shutdownSystem();  // Shut down everything
    return;  // Exit loop to prevent any further operations
  }

  if (currentState == LOW && buttonState == true) {  // Button is pressed
    overflowDetected = false;  // Reset overflow detection flag
    systemEnabled = true;  // Enable system
    buttonState = false;  // Set button state to false
    waterDetected = false;  // Reset water detection flag
    motorRunning = false;  // Reset motor running flag
    
    systemStartup();  // Start up sequence: LED blink and buzzer
  }
  
  if (currentState == HIGH) {  // Button is released
    buttonState = true;  // Set button state to true
  }
  
  if (systemEnabled) {
    if (!waterDetected) {
      // Open solenoid valve
      digitalWrite(Solenoid_Pin, HIGH);  // Turn ON the solenoid relay
      
      // Wait for water level to reach desired level
      while (digitalRead(Liquid_Detection_Pin) == HIGH) {
        // Check for overflow during water filling
        if (digitalRead(Overflow_Sensor_Pin) == LOW) {  // Check overflow sensor
          shutdown