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.