hello guys. i hope someone can help me on this project.
my project is based on ultrasonic sensor. measuring water volume in the rectangular tank by using arduino and ultrsonic sensor. so basically i use ultrasonic sensor to measure distance and then manipulate the distance to calculate volume of water in a rectangular tank.
first i need to measure the initial distance between sensor and empty base tank.
second, fill the rectangular tank with water.
third, measure the distance from sensor to water surface.
fourth, calculate the difference between initial distance and distance of sensor to water surface to get height of water in the rectangular tank.
fifth, calculate the volume of the water in the tank using basic rectangular volume which is height x surface area of tank based.
lastly, show the volume measurement to lcd.
so i used arduino uno, ultrasonic sensor, jumper wires, lcd.
may i know how to get the coding?
EDIT: THIS IS MY LATEST CODING. IS THERE ANYWAY I CAN IMPROVE THIS SO I DO NOT NEED ENTER VALUE OF INITIAL DISTANCE MANUALLY IN THE CODING EVERYTIME I WANT TO START THE PROTOTYPE AND MEASURE DIFFERENT TANK? MEANS I NEED THE SENSOR WILL MEASURE AND AUTOMATICALLY BECOME THE INPUT OF THE CODING AS INITIAL DISTANCE.
const int trigPin = 12;
const int echoPin = 11;
float initialdistance = 40; // insert initial distance or distance between sensor and empty base tank
float surfacearea = 10; // enter value of surface area of the rectangular tank base by multiplying width and length
float duration, distance, heightofwater, volume;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
heightofwater = initialdistance-distance;
volume = heightofwater*surfacearea;
Serial.print("Distance: ");
Serial.println(distance);
delay(1000);
Serial.print("Volume: ");
Serial.println(volume);
delay(1000);
}