Friday, October 24, 2014

On temperature sensors

Temperature sensors! We've all at some point played with one of those. Be it that water temperature sensing application or the thermostat in a car. There are several types of sensors and going through all those data sheets would reveal that there are disparities between them. In this post, I'll try to present some sensors based on stuff I've seen.

1. The Analog sensor or thermostat or thermistor
Okay, this is the one. I'm pretty sure all DIY hackers have seen this one. A thermistor is basically a resistor whose resistance varies with temperature. Just like the LDR's resistance varies with light incident on it. So what does it look like?
Figure 1 shows basic thermistors. Those two are identical except for their temperature ratings. When you ask for a thermistor at the electronic shop, this is what you'll most likely end up with.


Figure 1: The basic thermistor

Sometimes, you'll be working on a project where you'll be measuring the temperature of a liquid(maybe water). The water proof thermistor is what you might be using. It is shown in figure 2.


Figure 2: Waterproof thermistor(right)

So is it any good? I think that if 
1) You need a simple temp sensing solution. This is for you.
2) You have tons of analog ports on your microcontroller. This is for you.
3) You are not bothered with a great deal of accuracy. This is for you.
4) You are looking for a very cheap solution(Less than Rs 50 in mauritius). This is for you.

So, simplicity and low cost are the key words here. So how to make that work? This is a variable resistor and so to get something coherent out of it, we fall back to our good old voltage divider circuit. Figure 3 gives a brief recap.



Figure 3: Voltage divider recap(Quality is top class, I know :p)

So, A gives a basic voltage divider circuit. To keep it simple, if you have a closed circuit with a DC source and two resistors, the voltage is going to be divided at some points. For instance, at Vo, the voltage is given by equation B. Now, suppose you take R1 and replace it with a variable resistance(for instance, the thermistor) - if temperature changes, Vo will change. That's it for the maths.
C gives how you should set the circuit up if you are using a microcontroller. Usually, if your thermistor is rated 10k, R should be 10k. And then it's quite easy to convert the analog data to some coherent temperature value. If you really dig up stuff, you are gonna be facing terms like NTC, PTC. But if you don't really want to bother yourself with the maths, here you go. If you're using the UNO(or Pro or Mega), 1024 is the highest analog reading you are ever going to read. So, lets call the analog reading you are getting TEMPRAW. Also, lets say Rt is thermistor resistance and R is the value of the fixed resistor. Figure 4 gives the relevant equations.


Figure 5: Thermistor equations

So that's it, a very simple means of getting temperature data. Next up, the analog temperature sensor.

2. TMP36 -Analog temperature sensor
Okay, I have a bit of a personal history with the TMP 36. I never managed to get a working one - I think it's just bad luck :/ . So, how does it look like? It's very similar to a transistor and it's extremely easy to use. And if you are looking for a quick upgrade in terms of accuracy over the thermistor, you have a deal. This beautiful piece of electronics offers an accuracy of 0.1 degrees celcius. Figure 6 gives you info on pinouts and how to set it up. 


Figure 6: Art ain't in me

Now that you have Vo fed to your analog pin, the conversion step is much easier than for a thermistor. The TMP36 has a sensitivity of 20mV/degrees C. This implies that for every degree celcius change, you are getting 20mV. Now, you'll be reading stuff from 0 to 1023. To get voltage from this value, you'll have take this value, multiply it by 5000(assuming you are using 5V) and divide it by 1024. To get a degrees C reading, take the voltage, substract 500 and divide by 10.
Next up, a personal favorite, the DS18B20.

3. Digital temperature sensor, DS18B20

I came across the DS18B20 because I had run out of analog pins for a project. It is a wonderful sensor in terms of functionality.It saves you the precious analog pins and that makes it stand out. The downside of this sensor is the sheer complexity of getting a reading out of it. So complex it is that people have produced libraries for it. So if you want this sensor, the onewire.h library is essential.
Another issue you might be facing is conversion time. The resolution of this thing is adjustable from 9 bit to 12 bits. At 12 bits, conversion time is 750ms. 750ms! In real time applications, you are going to get in trouble with this. I set it up for 9 bits and this reduces conversion time to just 93.7ms. A more acceptable value. So I did not find software to do that. I tweaked the existing code a little bit and it just worked. You might want to dig in the datasheet for that one.

Next week - PCB printing in Mauritius!


No comments:

Post a Comment