The sensor is an old water level meter that I got from a local industrial company, they told me it worked (it does) but they have to replace them every 20 years. It’s powered by 24V and outputs a 4-20mA signal; it seems to be an old industrial standard.
I made a simple circuit with an OP-Amp measuring the voltage drop over a resistor, the OP-AMP has a gain of 100 so the signal out is 400-2000 mV!
There is however a linearity problem with the OP-Amp and I want to solve this in software.
I’ve done some testing with the sensor and come up with a polynomial function describing the measured signal but I’m not sure how I can apply this to my code.
The testing was conducted by using the multi meter to measure current and a multi meter to measure the voltage output from the OP-Amp, I made 4 identical circuits and had 5 test points for each test. I then put them the data into excel and used the graph function to display it and create a poly-function of it. It’s just an error of 3-4% but it’s still nice learning how to do things properly!
Below is an image of the averaged graph and the poly-function.
Is there a better way to doing this?
I am aware that I could use multimap but I want to learn something, so would prefer to use the "harder" way
Thanks in advance for any help!
Poly-function: y = -5,0833x^4 + 74x^3 - 369,92x^2 + 875x - 411