I got my DF robotshop rover a few weeks ago and have been playing around with the temp sensor. I’ve seen the questions posted about how to read the LM35 temp sensor; but no real answers.
Here’s how to read the values:
Degres Centigrade = (analogRead(a1) / 1024) * 500
Degres Fahrenheit = (analogRead(a1) / 1024) * 900 + 32
If that sounds too simple, here’s how I got there:
- The chip’s spec sheet show .01 V/ deg C output.
This means that the sensor puts out a value of about 52-56 at room temp based on the AtMega’s “normal” readings of analog inputs. This means that the analog inputs see a value of 54 based on 1024 pieces of resolution on a 5v signal.
I’ll break down the readings further:
56 ([sensor reading]) / 1024 (full signal)
= 56/1024 * 5 volts
= .2734ish volts (actual sensor output if you read directly with multimeter)
If we know the sensor puts out .01V/deg, that means it is about 27 degrees C in the room (81 F).
I simplify the longhand equation:
([sensor reading]/1024) * 5 / .01
into
([sensor reading]/1024) * 500
and that will read Degrees Centegrade
And for Fahrenheit I blend in the C to F conversion (F = C * 9 / 5 + 32):
Longhand:
([sensor reading]/1024) * 5 / .01 * ( 9 / 5 ) + 32
into:
([sensor reading]/1024) * 900 + 32
The readings still sound high, but I verified them against my infrared temperature sensor. The board seems to run about 7-10 degrees hotter than the room