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.
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
/*
* 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)) {