#include <LiquidCrystal_I2C.h> // liquidcrystal i2c
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int distance[6];
void setup() {
Serial.begin(115200);
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn LCD light ON
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print(" W H L ");// print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (0, 0)
lcd.print(" Volume = ");// print message at (0, 0)
for (int i=15; i<=17; i++) {
pinMode(i, INPUT); // Set Pin2 as Input Pin (connected to ECHO Pin)
}
pinMode(A0, OUTPUT); // Set Pin3 as Output Pin (connected to TRIG Pin)
}
void loop() {
int j = 2;
// Start a new measurement:
for (int i=15; i<=17; i++) {
digitalWrite(A0, HIGH); // Start sending the UltraSound Sound
delayMicroseconds(10); // Sending Duration 10uSec.
digitalWrite(A0, LOW); // End sending the UltraSound Sound
// Read the result:
distance[i] = pulseIn(i, HIGH) / 58;
lcd.setCursor(j, 0); // move cursor to (2, 1)
lcd.print(" "); // Clear The Screen at (2, 1)
lcd.setCursor(j, 0); // move cursor to (2, 1)
lcd.print(distance[i]); // print message at (2, 1)
if (j <16) {j = j + 5; } else {j = 1;}
delay(50);
}
long Volume = distance[15] * distance[16] * distance[17];
lcd.setCursor(10, 1);
lcd.print(" ");// print message at (0, 0)
lcd.setCursor(10, 1); // move cursor to (0, 0)
lcd.print(Volume);// print message at (0, 0)
delay(100);
}