protaa Posted 16 hours ago Posted 16 hours ago 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); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.