[SOLVED] How to calculate water depth using a set of ADC parameters available?

Thread Starter

UKB

Joined Jul 19, 2024
5
Hello,
I am working on a project that is supposed to measure the water depth using a water level sensor connected to an analog input pin of an IO controller (10bit ADC, Analog Input resolution – 10mV).
Following are the set of parameters available to me

uint8_t max_vdd = 5; //!< supply to the water level (in V)
uint16_t min_depth_adc = 10; //!< 10-bit adc count representing 0m
uint16_t max_depth_adc = 1000; //!< 10-bit adc count representing max depth
uint16_t min_depth_mv = 200; //!< voltage measured at 0m depth, stored as millivolt
uint16_t max_depth_mv = 4800; //!< voltage measured at max depth (lowest) as millivolt
uint16_t max_depth = 10; //!< in meters, min_depth = 0m
int16_t offset_mv = -30; //!< signed offset adjustment in mV, default = 0

What would be the formula for calculating the water depth in meters?
 

Ian0

Joined Aug 7, 2020
13,097
Do you have the reading from the sensor at the depth you wish to measure? Is it in adc count or in millivolts?
Is this homework?
 

MrChips

Joined Oct 2, 2009
34,628
You can use the raw ADC counts and ignore everything else.
The equation of a straight line is
y = mx + c
where m is the slope and c is the intercept on the y-axis when x = 0.

m is calculated from knowing a pair of coordinates.
m = (y1 - y2) / (x1 - x2)
c = y - mx
 

Thread Starter

UKB

Joined Jul 19, 2024
5
Hi @MrChips and @Ian0, I presume, you mean "Analog Voltage measured (mv)" in y axis and "ADC count obtained" in x axis. Using the slope equation, how does that translate to water depth in metres?
 

BobTPH

Joined Jun 5, 2013
11,463
Thanks @MrChips, I shall wait for some more suggestions that could use all of the parameters that I mentioned in my query.
They are redundant! You can calculate it with either the two ADC counts or the two voltages.

The extra step of converting one to the other does not change the problem at all. So, unless they are needed for some other purpose, there is no reason to use them.
 

Thread Starter

UKB

Joined Jul 19, 2024
5
Thank you all and as suggested by you all, having "water level" in the x coordinate and "ADC count" in the y coordinate, and using the straight line equation, I calculated the water level for the measured ADC count.
 
Top