/**
HC-SR04 Distance Sensor Example
https://wokwi.com/arduino/projects/304444938977804866
*/
#define PIN_TRIG 3
#define PIN_ECHO 2
void setup() {
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
}
void loop() {
double raio = 4;
double volmax = 500;
double h=0;
double volume = 0;
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result:
int duration = pulseIn(PIN_ECHO, HIGH);
h = duration / 58;
Serial.println(h);
volume = 3.1416*raio*raio*(403-h);
Serial.print("Volume: ");
Serial.println(volume);
delay(1000);
}