Reputation: 621
I see formula like
temp = (5*val*100/1024)
Can anyone tell me the details of this formula?
Upvotes: 3
Views: 36842
Reputation: 11
for Arduinos;
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
Upvotes: 1
Reputation: 24802
the truth always lies within the datasheets:
Your Atmega is powered by 5V, and the datasheet of the Atmega states that its ADC has a definition of 1024 values (i.e. 10bits). So in your formula, 5/1024
is representing each voltage step represented by a bit:
0.0000V -> 0b0000000000
0.0048V -> 0b0000000001
...
5.0000V -> 0b1000000000
If you read the application notes in the LM35 datasheet, you'll find the following formula:
Vout=10mV/°C
if you're binding the LM35 with a 200ohms resistor. So if you use the rule of three, you'll get:
Vout=0.01/°C
°C=Vout/0.01
°C=Vout/0.01
°C=Vout*100
HTH
Upvotes: 6