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

Arduino UNO-Based Water Management System with Ultrasonic Sensors and Solenoid Valves

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Water Management System with Ultrasonic Sensors and Solenoid Valves

Circuit Documentation

Summary

This document provides a detailed overview of a water management system controlled by an Arduino UNO. The system uses ultrasonic sensors to detect objects, water flow sensors to monitor water flow, and solenoid valves to control water flow. The system operates three sets of sensors and valves, ensuring water flow is managed based on object detection and flow rate.

Component List

  1. Plastic Solenoid Valve

    • Description: Controls the flow of water.
    • Pins: pin1, pin2
  2. ULN2803 Darlington Array

    • Description: Used to drive the solenoid valves.
    • Pins: I1, I2, I3, I4, I5, I6, I7, I8, O1, O2, O3, O4, O5, O6, O7, O8, GND, COMMON
  3. Arduino UNO

    • Description: Microcontroller used to control the entire system.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  4. HC-SR04 Ultrasonic Sensor

    • Description: Used to detect objects.
    • Pins: VCC, TRIG, ECHO, GND
  5. YF-S201 Water Flow Meter

    • Description: Measures the flow rate of water.
    • Pins: SIG, GND, VCC
  6. POWER SUPPLY 12V 5AMP

    • Description: Provides power to the system.
    • Pins: 220V Positive Pole (AC), 220V Negative Pole (AC), GND, GND (DC), 12V-24V Output (DC)
  7. Terminal Block

    • Description: Used for connecting multiple wires.
    • Pins: 1, 2, 3, 4, 5, 6, 7, 8
  8. Power 220V

    • Description: Provides 220V AC power.
    • Pins: hot wire, neutral wire

Wiring Details

Plastic Solenoid Valve

ULN2803 Darlington Array

Arduino UNO

HC-SR04 Ultrasonic Sensor

YF-S201 Water Flow Meter

POWER SUPPLY 12V 5AMP

Terminal Block

Power 220V

Code Documentation

/*
 * Arduino-Controlled Water Management System with Ultrasonic Sensing and
 * Solenoid Valves
 *
 * This code controls a water management system using an Arduino UNO. It
 * interfaces with ultrasonic sensors to detect objects, water flow sensors to
 * monitor water flow, and solenoid valves to control water flow. The system
 * operates three sets of sensors and valves, ensuring water flow is managed
 * based on object detection and flow rate.
 */

#define TRIG_PIN1 11
#define ECHO_PIN1 10
#define TRIG_PIN2 6
#define ECHO_PIN2 5
#define FS1 9
#define FS2 8
#define FS3 7
#define SV1 2
#define SV2 3
#define SV3 4

const float soundSpeed = 343.0; // Speed of sound in m/s
const float maxDistance = 0.3; // Max distance to check for objects (in meters)

bool isObjectDetected(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  unsigned long duration = pulseIn(echoPin, HIGH);
  float distance = (duration * soundSpeed) / (2 * 1000); // Convert to meters
  return (distance <= maxDistance);
}

void controlSolenoid(int solenoidPin, bool state) {
  digitalWrite(solenoidPin, state ? HIGH : LOW);
}

void setup() {
  Serial.begin(9600);
  pinMode(ECHO_PIN1, INPUT);
  pinMode(TRIG_PIN1, OUTPUT);
  pinMode(TRIG_PIN2, OUTPUT);
  pinMode(ECHO_PIN2, INPUT);
  pinMode(FS1, INPUT);
  pinMode(FS2, INPUT);
  pinMode(FS3, INPUT);
  pinMode(SV1, OUTPUT);
  pinMode(SV2, OUTPUT);
  pinMode(SV3, OUTPUT);
  digitalWrite(SV1, LOW);
  digitalWrite(SV2, LOW);
  digitalWrite(SV3, LOW);
}

void checkAndControlFlow(int flowSensorPin, int solenoidPin, int trigPin, int echoPin) {
  if (!isObjectDetected(trigPin, echoPin)) {
    Serial.println("No user detected.");
    int flowRate = digitalRead(flowSensorPin);
    controlSolenoid(solenoidPin, flowRate > 0);
  } else {
    controlSolenoid(solenoidPin, LOW);
    Serial.println("User is detected.");
  }
}

void loop() {
  checkAndControlFlow(FS1, SV1, TRIG_PIN1, ECHO_PIN1);
  checkAndControlFlow(FS2, SV2, TRIG_PIN2, ECHO_PIN2);
  if (!isObjectDetected(TRIG_PIN1, ECHO_PIN1) && !isObjectDetected(TRIG_PIN2, ECHO_PIN2)) {