#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
//#include <ESPAsyncWebServer.h>
//#include "index.h" // Include the index.h file
// SDA to 20 pin and SCL to 21 pin
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
//UltraSonicS pins
#define trigPinS 12
#define echoPinS 13
float UltraS(){
float duration;
float distance;
// Clears the trigPin
digitalWrite(trigPinS, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPinS, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinS, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPinS, HIGH);
// Calculating the distance
distance = 10 * duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
//Serial.print("Distance : ");
return distance;
}
//////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
//UltraSonic
pinMode(trigPinS, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPinS, INPUT); // Sets the echoPin as an Input
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(2,0); //Set cursor to character 2 on line 0
lcd.print("Milk Volume");
lcd.setCursor(2,1); //Move cursor to character 2 on line 1
lcd.print("Calculator");
}
///////////////////////////////////////////
int w = 274;
int l = 122;
int A = w * l;
float V = 0;
int H = 2000; // Hight to the UltraSonic from Tank bottom
void loop() {
int h = H - UltraS();
int v = A * h;
V = v/1000000;
////////////////////////////////////////
lcd.clear();
lcd.setCursor(2,0); //Set cursor to character 2 on line 0
lcd.print("Milk Volume");
lcd.setCursor(1,1); //Move cursor to character 2 on line 1
lcd.print(V);
lcd.setCursor(7,1);
lcd.print(" m^3");
//////////////////////////////////////////////////////////////////////////
Serial.println("------------------------------------------------------------------------------------------------------");
Serial.println(" ###### Milk Volume Measuring System ######");
Serial.println(" ");
Serial.println("Date :- 06/04/2024");
Serial.println("Time :- 13:00 ");
Serial.println("");
Serial.println(" Parameters");
Serial.println("");
Serial.print(" Tank Width (w) cm : ");Serial.println(w);
Serial.print(" Tank Length (l) cm : ");Serial.println(l);
Serial.print(" Area (A) cm^2 : ");Serial.println(A);
Serial.print(" Milk level cm : ");Serial.println(h);
Serial.print(" Milk Volume (m^3) : ");Serial.println(V);
/////////////////////////////////////////////////////////////////////////////////
delay(500);
}