/*
Smoothing
Reads repeatedly from an analog input, calculating a running average and
printing it to the computer. Keeps ten readings in an array and continually
averages them.
The circuit:
- analog sensor (potentiometer will do) attached to analog input 0
created 22 Apr 2007
by David A. Mellis <[email protected]>
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Smoothing
*/
// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
const float Length1 = 615 ; // cm
const float Height1 = 150 ; // cm
const float Width1 = 220 ; // cm
const float Length2 = 585 ; // cm
const float Height2 = 140 ; // cm
const float Width2 = 220 ; // cm
long Distance1;
long Distance2;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("MONITORING DOTP");
lcd.setCursor(0,1);
lcd.print("UTILITY-PROJECT");
lcd.setCursor(0,2);
lcd.print("PT.PORTO INDONESIA");
lcd.setCursor(0,3);
lcd.print("Updt:11/01/23|01:46");
delay(5000);
lcd.clear();
}
void loop() {
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
delay(500); // delay in between reads for stability
//==================Kedalaman===================\\
float value = map(average,200,1023,0,1023);
int Depth1 = (value / 1023.00) * 200; //cm
double acosine = acos (1-(2 * (Depth1)/Height1));
long Volume = ( (Height1 * Width1 * Length1 / 4) * ( (acosine) - ((1 - (2*Depth1/Height1)) * (sqrt((4*Depth1/Height1) - ((4* Depth1*Depth1)/(Height1*Height1)))))) );
Volume = Volume/1000;
int volume_C = Volume;
Serial.print("Analog: " + (String)average);
Serial.print(" | Depth.1: " + (String)Depth1);
Serial.print(" Cm");
Serial.print(" | V.DOTP1: " + (String)Volume);
Serial.println(" L");
lcd.setCursor(0,0);
lcd.print("Depth.1:" + (String)Depth1);
lcd.print(" Cm ");
lcd.setCursor(0,1);
lcd.print("V.DOTP1:" + (String)Volume);
lcd.print(" L ");
if(Volume >16000 || Volume <0){
lcd.clear();
// }
}