Then too maybe because nobody knows what A/D the thread starter has? The basics are the basics but without knowing what they have it's sort of hard to get specific as to a calibration procedure and method. While the classic Y=MX+B is the classic slope intercept it also assumes a simple straight line equation which all A/D converters do not always have. The ESP32 is a good example of an A/D converter which is not linear. The Atmel 328P on the other hand, popular in some Arduino boards is a pretty linear 10 bit A/D. Less knowing exactly what the thread starter has it's pretty hard to give good advice application specific.I find it interesting that no one has described or linked to any sort of calibration procedure. Here is how I have done it.
First we need to know the relationship from input to output, typically this is a linear relationship, meaning a straight line as we learned in high school;
Y = m * X + B eq 1
where: X is what we input
Y is what we read out of the A/D
B is the zero offset.
m is the slope of the line
To calibrate such a system we need to take two readings, one close to the bottom (X1, Y1) and one close to the top (X2, Y2). By "close" I mean where the output is changing uniformly with the input, so we are past any offset clipping and the like.
With our two measurements we can compute the slope:
m = delta Y / delta X = (Y2 - Y1) / (X2 - X1)
Now plug in either pair into eq 1 to compute B.
If you are on a "powerful enough" controller doing this using floating point numbers is fine, but in a resource limited micro it is usually best to pick the units such that m and B are integers. Once the reading is computed the decimal point (or binary point) may be shifted to get a more useful result.
Just My Take...
Ron