NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Everything Else » How to get a more accurate temperature
October 04, 2011 by glendon |
Hi, I got the temperature sensor project working but it gives 29.5 degree celsius. I feels it's slightly too high for my room (esp. when it just rained and I have my windows opened). The PDF guide says that to get a more accurate reading, we need to calibrate the reference voltage (which is a constant +5V for the project). Can someone suggest some simple calibration ways I can try out to achieve a more accurate reading? By the way, I have a computer science degree (so programming is second nature to me), but all my understanding of electronics comes solely from my experimenting with the NerdKits. Hence, kindly keep your suggestions/explanations simple for a layman like me. Thanks in advance. |
---|---|
October 05, 2011 by Ralphxyz |
Hi glendon, first thing the "reference voltage" is most likely not 5 volts. You need to test your power supply to find the true reference voltage. The Nerdkit furnished tempsensor actually come in three versions with the more accurate sensor costing a lot more, relatively speaking. You can go to a electronics supplier to get a more accurate sensor. There are discussions here in the forum where people got more accuracy out of the supplied tempsensor. Also since you are comfortable with the programing you could also program in a curve once you have established how far off the accuracy is. You would need a reference thermometer to do the programing calibration. Ralph |
October 05, 2011 by bretm |
You can also tell the ADC to measure the 1.1V band gap voltage reference built in to the MCU instead of an external voltage. You can use that result to calculate the AREF value. But that's still not super accurate. There's also a register called DIDR or something like that, whcih you can use to disengage the digital input circuitry on the analog input pins. Also, don't use the other PORTC pins while taking a measurement. You can also put the MCU to sleep. When you do that while ADC is enabled, it will start a conversion. The quiet sleepy time will eliminate some more measurement noise. But external calibration is best. |
October 05, 2011 by mrobbins (NerdKits Staff) |
Hi glendon, I'd suggest you mentally split the calibration problem into two pieces:
You have to address both pieces in order to get an accurate reading. I'd suggest you do #2 first, because it's relatively easy (using a digital multimeter that you trust) to do. If you remove the LM34 and make a little voltage divider with two resistors (VCC -- 10K --- 10K --- GND, with the middle point connected to the analog in pin), you'll have a voltage that's roughly 2.5V. Measure that voltage to ground with a digital multimeter, and grab as many digits as you can. Then, using the tempsensor code, look at the average temperature reading that's shown. Just to play with numbers, let's say your multimeter measured 2.480 volts, and the NerdKits LCD with the normal tempsensor code says it says 252.67 degrees. The normal tempsensor code has a line like this in it:
But if you've actually measured otherwise, we can "fix" this expression. If our code says 252.67 degrees, then its average 10-bit ADC sample must have been:
Then, we can change our expression to be something like:
That means we take sample, multiply by the ratio (2.480 volts / 517.5 ADC scale), to get a voltage, and then multiply by the ratio (1 degree F / 0.010 volts). So now recompile and give that a try. If you still have the same resistors in, and if we're still pretending you measured 2.480 volts with the multimeter, now you ought to see roughly 248.00 degrees showing on the LCD. (Side note: this assumes that the zero-offset of the ADC is good. But we're going to take care of offset in the next step. Also, if the power supply voltage changes, such as if your battery gets low or you start drawing more current through the 7805, or you're relying on your computer to provide USB power, you're still in trouble. bretm's comment about using a band gap voltage reference or other external voltage reference is a good one. Let me put it in bold: the accuracy of your measurement is indeed limited by the accuracy (or at the very least consistency) of your voltage reference.) The second part is to calibrate for your particular LM34's voltage offset. Remove your two resistors and put the LM34 back in place. Take a look at this thread which looks at the accuracy of the LM34s and how much variation you might expect -- real devices have offset which is unavoidable, even if you pay big bucks for the more accurate versions of the sensor. In-system calibration is often unavoidable for something like this. For this, you're just going to need a "reference thermometer", just as Ralph suggests. But if you believe that it's truly X degrees in your room, and the system (post-ADC calibration above) says that it's Y degrees, then you can just add an offset, subtracting the difference. Hope that helps! Mike |
October 10, 2011 by glendon |
Thanks for all your responses. Mike, I'll give the voltage divider a try soon. But may I know why halving the voltage will give a more accurate reference voltage? Thanks. |
October 11, 2011 by bretm |
It doesn't make it more accurate, it just moves it away from +5V. If the voltage is approximately 5V it might be slightly over 5V in which case the ADC won't be able to make a valid measurement. If you move it down to 2.5V and it's slightly off, then it's still well within the linear range of the ADC. |
October 11, 2011 by glendon |
Understood. Thanks a bunch, bretm! :) |
October 31, 2011 by thomas0826 |
Good morning Glendon, another thought to help stabilize the voltage woule be to put an electrolytic capacitor (maybe 100uf at 10 volts [watch the polarity]) across the positive and negitave on your breadboard after the regulator, this will absorbe small voltage swings, and using 1% precision resistors also as they very with temperature. Tom |
April 24, 2012 by jlaskowski |
Just breaking out my digital multimeter and testing the voltage between the breadboard rails gave me 4910mV. Making this change in the formula gave me a more accurate temperature reading. Of all the suggestions above, this test and code change seems like the easiest way to get a more accurate temp reading.
|
June 22, 2012 by HansRoaming |
To get rid of some of the noise I converted the code to be interrupt driven, that is to shut down the MCU whilst taking the measurement and having it wake up when the conversion is done.
|
Please log in to post a reply.
Did you know that interrupts can cause problems if you're not careful about timing and memory access? Learn more...
|