Jump to content

Recommended Posts

Posted

Overview:

This project uses an ultrasonic sensor (HC-SR04) to measure the water level in a tank. The measured distance is used to calculate the water level, which is then displayed via Serial Monitor or LCD (optional). It's useful for automating tank refills or monitoring water levels in remote locations.

Requirements:

  • Arduino Uno (or any compatible board)

  • HC-SR04 Ultrasonic Sensor

  • Breadboard and jumper wires

  • USB Cable for Arduino

  • (Optional) 16x2 LCD with I2C module

  • (Optional) Buzzer or LED for low water alert

  • Power supply (e.g., USB or battery)

 

Wiring / Circuit Diagram:

Basic Connections (without LCD):

 

HC-SR04 Pin Arduino Pin
VCC 5V
GND GND
TRIG D9

ECHO

D10   

  

Source Code:

#define trigPin 9
#define echoPin 10

long duration;
float distance;
float tankHeight = 30.0;  // in cm — adjust to match your tank height

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // Send ultrasonic pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read echo time
  duration = pulseIn(echoPin, HIGH);

  // Convert to distance
  distance = duration * 0.034 / 2;

  // Calculate water level
  float waterLevel = tankHeight - distance;
  if (waterLevel < 0) waterLevel = 0;

  Serial.print("Water Level: ");
  Serial.print(waterLevel);
  Serial.println(" cm");

  delay(1000);
}
 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.