It has in it a nice lookup table of resistance vs temperature. I'd like to read it using my Teensy Arduino but I'm not sure of the best method. This must have been done before. My immediate thought was to try to find the equation for the curve but running it through some calculators didn't yield a good fit, so I guess I'll need to read the position in the table then interpolate (thought I guess this is never going to be perfect as this would be a linear interpolation..?)
Here's the lookup table:
Temp vs Resistance (would need to convert this to volts)
|-40|45313|
|-30|26114|
|-20|15462|
|-10|9397|
|0|5896|
|10|3792|
|20|2500|
|30|1707|
|40|1175|
|50|834|
|60|596|
|70|436|
|80|323|
|90|243|
|100|187|
|110|144|
|120|113|
|130|89|
Has anyone got a good suggestion of some example code to go off of?
It's a thermistor. There are calculators on the Internet that will give you the Steinhart-Hart coefficients when you feed them several pairs of temperatures and resistances. The coefficients can then be used in the Steinhart-Hart equation to convert resistance to temperature. That will give you a continuous solution and not a step-wise interpolation.
There are MANY examples of Arduino sketches for reading a thermistor. There are probably a few libraries, too.
Thanks John, I've had a search and you are right! I will use one of these... Reading up on them though raises one more question...
These calculations all rely on a reference resistor, for example 1k. In my case the thermistor will be running on a 5v supply, and I'll be using a Teensy 3.2 to interpret the signal, an I'm guessing the sensor doesn't have a built in ref resistor (it doesn't mention one on the datasheet).
As such, I was already planning to use a voltage divider to scale the input range down to 0-3.3v. The voltage divider is R1 = 10k, R2 = 20k, with a 100nF capacitor between the arduino input and ground to smooth the signal. In this case, where do I put the reference resistor for the thermistor? Before the voltage divider or after, on the arduino input pin?
Why are you making this more complicated than it needs to be? Use the 3.3V output on the Teensy, instead of the 5V output, then you will not need a voltage divider.
Because these sensors will be run from the engine wiring harness and will receive 5v from another part of the loom. Will need to work with a 5v system unfortunately as running 3v3 would be quite complicated in this instance from a hardware perspective.
Ok, fair enough. Such questions can often be avoided by giving a little more background info on your project.
The data sheet is a little unclear. Is this one of those sensors where one of the terminals is the metal body, and so must be used as ground, because it is in contact with the chassis?
Thanks very much Paul! That's really helpful. I'll make a little test circuit and give it a go. It's a 2 wire type so it will have a 5v in and a ground pin but I should be able to achieve the circuit you show above.
May I ask how you picked the values for R2 and R3? And what would you use for R1? I think from my calculation 1K should work?
There are various voltage-divider- calculators on the web. But most of them calculate resistor values that don't correspond to the common series of values that resistors are manufactured in. So I like to use one where you can specify which resistor series you want to use, and it suggests what combinations of those will give you the output voltage closest to what you want. Here's an example.
If it has 5V in and ground, it would need to be a 3-pin type, the 3rd pin being a voltage output representing the temp. If that's the case, you don't need a reference resistor.
Perhaps the ground terminal is the metal body, as I suggested earlier, and the other 2 are 5V in and voltage output?
Sorry I wasn't very clear in that reply - I mean it's got 2 pins and it's literally just a thermistor inside so you could run it high to low or low to high. Ah I see that's a 5v to 3v3 divide - excellent, I had used 10k and 20k but it's the same ratio so should be good if I add a 1k resistor as you have drawn it
It's the same as in the picture above from PaulRB, where R1 = 1000, R2 = 10000, R3 = 20000
Since R2 and R3 are just a voltage divider from 5v to 3v3, I think I can ignore that part and treat it as if Vin was 3.3v, so I just need to solve to find the Sensor resistance knowing Vout as 1.186
Ah I think I may have found it... Does this seem correct?
I think that the nominal resistance (in your case: 2.5k?) is generally considered to be a good choice for the reference resistor.
It's too bad you can't provide voltage from the Teensy. The voltage divider formed by the thermistor and the reference resistor is 'ratiometric'. The absolute voltage is not important if it's the same voltage as the A/D reference. In other words, when the thermistor is at the nominal temperature (20°C?) the output will be 1/2 the operating voltage and analogRead() will return 511. It doesn't matter what the operating voltage is. 511 will always represent 20°C.
With two separate voltage sources, any changes in absolute voltage on either one will cause your reading to change.
Here's what I'm currently using; it seems to be working quite nicely and tracks up and down in temperature as expected with an ice pack around it. I'll need to do some testing with ice water and boiling water and see if it needs any tuning but for what I need it seems to do the trick.