#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int echoPin=3;
const int triggerPin=2;
long duration;
int distence=0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// variables to store the two numbers
int R = 0;
int H = 0;
float S=0;
float U=0;
float Q=0;
float volume=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(triggerPin,OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("welcom ");
lcd.setCursor(0,1);
lcd.print("TO MY PROJECT ");
delay(2000);
lcd.clear();
lcd.clear();
lcd.print("enter radius:");
// get the first number from the keypad
lcd.setCursor(0,1);
char key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
R = R * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
// clear the LCD and display message for the second number
lcd.clear();
lcd.print("enter Height:");
// get the second number from the keypad
lcd.setCursor(0,1);
key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
H = H * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
}
void loop() {
// put your main code here, to run repeatedly:lcd.clear();
// clear the LCD and display the two numbers
lcd.clear();
delay(300);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration=pulseIn(echoPin,HIGH);
distence=duration*0.034/2;
S=R*R*3.14;
U=distence*S;
Q=S*H;
volume =(Q-U)/1000;
lcd.setCursor(0,0);
lcd.print("volume (l); ");
lcd.setCursor(0,1);
lcd.print(volume);
lcd.setCursor(11,1);
lcd.print("litre");
delay(3000);
}