Bosch 0281006059 temp sensor

So, I'm experimentin with code on a homebrew piggyback ecu, and I came across a point where I needed to calibrate it to read the temperature, I chose bosch 0281006059 sensor (good range, availability and package). Pressure was easy. But temperature... At first my brain almost melted from math that might be involved- a good prelude to this topic is this thread:
bosch sensor

Becouse 73)(datasheet) of the non linear curve of the resistance in the temperature sensor I couldnt simply use map()
My simple solution that makes the temperature sensor at least work before polishing the code after calculating 20*C increment voltages after voltage divider using 6.6K :

double IAT()                                                                             /////////////////////////////////////////////////////////////////////////////
{
  double airTempduty = (analogRead(iatPin));        /////////////// 0281006059 bosch -40 to 150 C Could use of "curve magic formullas" figuring out
          

////// fragmented map of the sensor , must be a better way using a formulla.

  /// all temp is offset + 40
if (130<airTempduty<306)                                 /////calculated duty cycles for -40 and -20 etc.....
{
  float airTempmargin = map(airTempduty,130,306,0,20);
}
else if (306<airTempduty<541)
{
  float airTempmargin = map(airTempduty,306,541,20,40);
}
else if (541<airTempduty<743)
{
  float airTempmargin = map(airTempduty,541,743,40,60);
}
else if (743<airTempduty<869)
{
  float airTempmargin = map(airTempduty,743,869,60,80);
}
else if (869<airTempduty<940)
{
  float airTempmargin = map(airTempduty,869,940,80,100);
}
else if (940<airTempduty<976)
{
  float airTempmargin = map(airTempduty,940,976,100,120);
}
else if (976<airTempduty<996)
{
  float airTempmargin = map(airTempduty,976,996,120,140);
}
  // eliminate offset to Celsius and then convert to Kelvin
float airTempKelvin = airTempmargin+40+273.15;
  // Ensure only positive MAP values are returned:



  
  if(airTempKelvin < 0)
  {
    airTempKelvin = 0;
  }
  
  return airTempKelvin;
}

Looking for coding chads to chime in, am I missing a simpler solution.

Also want to use oxygen sensor as well -somebodyelses project with a table and a curve of the narowband o2 sensor in question should I map it the same as I did the temp sensor? It delivers 0-1 V sinusoidal signal and the average is the voltage in the table whats the best way to meassure it?

Hello!

Yes the temp side is difficult if i remember correctly some math work has to do.
The steinhart equation
You have to measure resistance at 3 point
Room temp, negative temp put in the freezer, and put in boiling water
Look up the equation and you will find

Einimas via Arduino Forum <notifications@arduino.discoursemail.com> ezt írta (időpont: 2022. dec. 6., Ke 18:03):

Thx, now I'll have to remember the first year of uni :smiley:

Good luck, but you can find it on the google maybe google has a calculator too!

Einimas via Arduino Forum <notifications@arduino.discoursemail.com> ezt írta (időpont: 2022. dec. 7., Sze 7:22):

The sensor i'm trying to use is used to calculate air density...

In this page i found "ait thermal expantion coeficient", if i'll look in to how close these curves are matching, might save me some calculations...

Havent tried steinhart equasion yet, was looking into optimizing other parts of the code.

With some observations found that my usable range of temperature is fairly linear and previous code with increased resolution should work fairly well.

Also the duty cycle read of the temperature sensor's usable range has linear enough corealation with air density, which I was looking after.

Curve of the sensors duty vs air density.

OK, so my "improvised mapping" as sampled in the first post didn't work at all... Go figure... but it was a good thought exercise and a learning experience. Now to find a way that works. This wonderfull article here popped up few days ago, might look into it, but from what I learned from others calculations like these take ~ 150ms which is too much. I've also calculated ABC in steinheart and that didnt led anywhere somebody please check it, I would be happy if there's a mistake there.

Now to try a insane solution thats simple and works.

I need to find a way to map a array of 885 values of usable duty cycle to degrees. [-50,-49,5,-49...........149,149.5,150] anyone knows if google sheets can spit those out of the graph in this array format?

Yeppe ka yeee....

After etempts of reinventing the wheel with polinomial function aproximations i came back to ol reliable Steinheart.

had to ajust the input to Y3 by +8 kelvin to correct for error and the output of the formulla was perfect ( used round() but still).

Now to to map it to an array.

If anyone comes across the problem with finding Steinheart coeficeants for bosch 0281006059 they are:
A 0,001305213816
B 0,0002582304849
C 0,0000001769345582

Reposting this google sheet with all the calculations, some aditionall formullas, that I was gonna use myself. Hope this helps others using this sensor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.