tmp36 Formula

I followed the instructions in the arduino starter book chapter 3 and everything worked great. I am curious about how the formula

float voltage = (sensorVal/1024.0) * 5.0

was arrived at in the book.

I downloaded the datasheet for the TMP36 and found the info concerning the -0.5V offset, but never found anything else about the values that the sensor outputs and the conversion needed to convert the values to voltages. I am interested in this only because in the future, if I use a different sensor, will there be a formula for it in the datasheet that I would be expected to find in order to get accurate data?

Did I miss it in the datasheet? All I saw was 10mV/degree C

I would have expected, with my limited knowledge, for it to give me a mV reading, not an integer value up to 1024 that would would need to be converted.

Any help would be appreciated,
robert

The micro controller has what is called an ADC (analog to digital converter). It takes the voltage and converts it to a 10bit value (as the arduino has a 10bit ADC on the analog pins).

The output voltage from the sensor is proportional to the input/supply voltage (in this case, the 5V from the arduino) and the common GND (0V).

This is where the formula comes from.

You have 0-5V spread over 10 bits...ie. 1024.

5V / 1024 = The resolution of voltage = about a change in 5mV is possible for this sensor using the 10 bit ADC of the TMP36.

Have a play with the "analog In" sketch in examples using a potentiometer to get the idea.

The TMP36 sensor is a “to voltage” sensor. analogRead() is used to measure voltages on pins.

Other sensors are available. Such as I2C devices which output values via the I2C protocol.
If you need more precision/range than the 10bits a light or temperature to voltage sensor can give, have a look at some I2C devices such as this: