/* Reading Voltage from Water Level Sensor
Sensor reads from 0 - 3 V
*/
//#include <elapsedMillis.h> //micros is also a thing
elapsedMillis timeVoltage;
const double sensor_wire_length = 600; // mm Depends on actual length
float voltage;
float water_level;
int analogValue;
float currTime;
void setup() {
pinMode(A0, INPUT); // reading the water level from 0-3V
Serial.begin(115200);
}
// Note Sampling Frequency is 1.23MHz //
void loop() {
analogValue = analogRead(A0);
voltage = analogValue / 1024. * 3; // Converts from 3 V
water_level = analogValue / 1024. * sensor_wire_length - (sensor_wire_length/2); // Converts to water level height, zeroing at mid line
currTime = timeVoltage;
Serial.print("Water Level: ");
Serial.println(water_level);
delay(100);
}