I am having difficulty getting my head around the right way to deal with a sensor drift issue I have. The reading from my light sensor varies with the environmental temperature. The manufacturer provides a graph that plots the offset in degrees for a spectrum of temperatures. The temperature offset is non-linear, so I can use the standard map()
function.
I added a temperature sensor to my circuit and now have access to a temperature variable. What I do with this? not too sure...
After reading up a bunch on seemingly-random methods for doing this, I am leaning towards trying to implement a linear interpolation solution. I have a two-dimensional array that contains both the temperature and offset variables from the manufacturer. Here it is:
float tempcompArray[2][21] = {{-25.0000,-20.0000,-15.0000,-10.0000,-5.0000,0.0000,5.0000,10.0000,15.0000,20.0000,25.0000,30.0000,35.0000,40.0000,45.0000,50.0000,55.0000,60.0000,65.0000,70.0000,75.0000},
{0.3035,0.3121,0.3209,0.3279,0.3367,0.3466,0.3540,0.3633,0.3731,0.3854,0.3966,0.4084,0.4228,0.4409,0.4637,0.4935,0.5386,0.5963,0.6877,0.8404,1.0439}};
Here is where I am stuck: how do I map from my super accurate temperature reading to return an interpolated offset? It seems like I need to be interpolating all over the place. The measurements from the manufacturer are taken every 5 degrees C. So I have 21 offset values corresponding with the factory measurements. But, I need to arrive at something that is an integer to be able to access the array element, right?
Argh, I am a bit lost. So much so, that I can't even figure out what to Google to find a better example.
Any guidance would be greatly appreciated.
Thank you.