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

Arduino-Controlled Ultrasonic Water Dispensing System

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Ultrasonic Water Dispensing System

Circuit Documentation

Summary

This circuit is designed to sense the presence of an object (such as an empty bottle) using an HC-SR04 Ultrasonic Distance Sensor and to control a Water Pump via a Relay Module based on the detected distance. The control logic is implemented on an Arduino UNO microcontroller. When the distance to the object is greater than 10 cm, the water pump is activated to dispense water. The circuit is powered by a 12V power supply, with the Arduino UNO and the HC-SR04 sensor receiving power from the Arduino's onboard voltage regulator.

Component List

Arduino UNO

HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)

RELAY MODULE

Water Pump

12V Power Supply

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)

RELAY MODULE

Water Pump

12V Power Supply

Documented Code

/*
 * Arduino Sketch for sensing an empty bottle and dispensing water
 * Components:
 * - Arduino UNO
 * - HC-SR04 Ultrasonic Distance Sensor
 * - Relay Module
 * - Water Pump
 *
 * Connections:
 * - HC-SR04 VCC to Arduino 5V
 * - HC-SR04 GND to Arduino GND
 * - HC-SR04 TRIG to Arduino D7
 * - HC-SR04 ECHO to Arduino D8
 * - Relay Module VCC to Arduino 5V
 * - Relay Module GND to Arduino GND
 * - Relay Module INPUT to Arduino D9
 * - Relay Module NC to Water Pump VCC
 * - Relay Module COM to 12V Power Supply -
 * - Water Pump GND to 12V Power Supply +
 */

#define TRIG_PIN 7
#define ECHO_PIN 8
#define RELAY_PIN 9

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Ensure relay is off initially
  Serial.begin(9600);
}

void loop() {
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1; // Convert to cm
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  if (distance > 10) { // If distance is greater than 10 cm
    digitalWrite(RELAY_PIN, HIGH); // Turn on the water pump
  } else {
    digitalWrite(RELAY_PIN, LOW); // Turn off the water pump
  }
  delay(1000); // Wait for 1 second before next measurement
}

This code is written for the Arduino UNO and is responsible for reading the distance from the HC-SR04 Ultrasonic Distance Sensor and controlling the Relay Module based on the distance measured. If the distance is greater than 10 cm, the relay is activated, which in turn powers the Water Pump. The relay is deactivated when the distance is less than or equal to 10 cm. The serial monitor outputs the measured distance for debugging purposes.