Thursday, November 26, 2009

Converting BMW temperature sensor resistance to degrees Celsius with an IC

The BMW E36 on-board computer uses a temperature sensor mounted in the front bumper.

The temperature sensor is actually a thermistor with a negative thermal coefficient (NTC thermistor = negistor), meaning that as the temperature rises, its resistance falls.

The sensor was found to be equal to a K164NK004.7 thermistor. The resistances of this thermistor for different temperatures according to the datasheet are:

When using an IC such as the Atmega168 on Arduino, you cannot measure resistance directly. You add a pull-up resistor to the temperature sensor, which creates a voltage divider and then use the IC to measure the resultant voltage.

The value dependence between the thermistor resistance and the resulting voltage is not linear and neither is the dependence between the resistance and the actual ambient temperature in degrees Celsius.

My goal was to determine the best value of the pull-up resistor to create a linear (or at least uniform) dependency between the ambient temperature and the output of the voltage divider.

I picked several common resistor values and calculated the voltages for different temperatures.

Let's put the values on a graph and see which resistor gives the most linear output

The graphs seem very similar, so let's graph the relation between a temperature change and a voltage change.

This graph clearly shows that no matter what resistance we use, we will never get a flat line. The next best thing is the 12K resistor - it is flat around zero degrees and uniform on both sides.

So let's use a 12K resistor and see how closely we can approximate its graph with a linear function. We want to calculate the temperature from the voltage, so the graph will be reversed. It is not hard to see that a good approximation function is

temperature = 20 * voltage - 45

That's not bad for such a simple function, but it still needs some fine-tuning - the biggest difference is almost 5 degrees Celsius.
After some test and error time, I came up with

temperature = (400 * voltage - 888) * (140 + |voltage|) / 3500

which gives acceptable results.

So let's sum up - if you connect the BMW E36 ambient temperature sensor to an IC and pull it up to 5V with a 12K resistor, you can then convert the voltage measured by the IC to actual temperature using the formula stated above.

Labels: , , ,


Anonymous said...

hello. i have a bmw E36 and my temperature sensor is missing. in that location i have only 2 wires. i have tried conecting a 4.7k thermistor but i get no values. in a few seconds after i start the ignition the display is showing 16 -13 -26 and it freezes in -37. am i missing something in this circuit ? can you help me ?

November 12, 2010 at 8:22 PM  
Blogger Jaroslav Klíma said...

Have you tried leaving it connected for a couple of hours? When you connect the thermistor after a long period of time, it needs time to start working (I don't know why).
You are not missing anything, I have been using a simple thermistor in place of the temperature sensor for two years now...

November 12, 2010 at 9:06 PM  
Anonymous Adam said...

Can I buy and use a K164NK004.7 thermistor instead of buy a new sensor from BMW?

November 10, 2011 at 9:25 AM  
Blogger Jaroslav Klíma said...

You certainly can, I have been using one for three years now. Just remember that it can take several hours before the OBC starts showing anything.

November 10, 2011 at 9:49 AM  
Anonymous Adam said...

Wow, that answer was fast, thank you! :D
Last week I retrofitted an OBC from an other car to my 318i.
My problem is: the temp. reading changes so slow. Example: maybe I can accept the 7°C that my OBC measured in the morning (8 AM, Budapest). After I went to my worksplace deep garage, 3 floors under the ground, where the temp. must be hihger than outside (and must be higher than 7°C I feel it :), but my OBC is keep showing 7°C.
I've just check the OBC again, it is still showing me 7°C :S
Is it normal, or should I suspect a faulty sensor?
thanks in advance

November 10, 2011 at 10:10 AM  
Anonymous Adam said...

Can I use something else instead of K164NK004.7? An other thermistor with the same parameters: -55÷125°C; 4,7kΩ; 450mW ?
thanks again

November 10, 2011 at 11:00 AM  
Blogger Jaroslav Klíma said...

I haven't seen a faulty temperature sensor yet, only disconnected and missing sensors.. The temperature reading changes one degree in about 10 seconds in my case, if I remember correctly.

Yes, you can use a different thermistor with the same specs.

November 20, 2011 at 4:31 PM  
Anonymous Anonymous said...

Hey, do you have the links for the pictures ?

February 21, 2013 at 1:50 PM  
Blogger Jaroslav Klíma said...

Thanks for alerting me. I've fixed the images.. please reload the page if you still don't see them.

February 21, 2013 at 11:18 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home