# Converting voltage reading from temperature sensor into Celcius

I'm learning how to read temperature reading from a sensor from this tutorial.

The code (Arduino) to convert from voltage reading into temperature is as follow.

float temperatureC = (voltage - 0.5) * 100 ; // Converting to degrees


I wonder why the formula has to be like this, the numbers and stuffs. Is it different from sensors to sensors? If I buy a temperature sensor, does it come with a specification on how derive temperature from voltage reading?

• Have you looked at the datasheet yet? – Ignacio Vazquez-Abrams Oct 11 '15 at 23:36
• No, my sensor come from an Arduino starter kit and I got no datasheet. Can I look it up online? – Andree Oct 11 '15 at 23:38

Typically for electronic components, there is a datasheet available which explains most of the stuff you need to know.

The TMP36 isn't different in that regard. So the datasheet is published by Analog Devices.

In it you will fine important ratings like which supply voltage range the device is made for (2.7V - 5.5V).

And of course there is a specification on the behavior of the temperature sensor.

Table 4 on page 8 gives us the values you find in your code:

Offset voltage: 0.5V and Output scaling: 10mV/°C

Which is what you are calculating.

Every sensor will be different and every will come with it's own specification. There are temperature sensors around with a digital interface, so you might have to do no conversion at all or have to calculate a strange polynomial function to get to the temperature.

I think the tutorial is a bit lacking in not telling you that there is a datasheet available. Datasheets are one of the most important things for engineers.

More complex devices (like a microcontroller) often come with a reference manual which covers the same stuff for all devices of a family and then there is a datasheet for each of the devices (or small family of devices).

Every different sensor will be different. The datasheet will give you either an expression that shows how the output voltage as a function of temperature or it will give you a graph in which case, you have to work out what the expression is.

The output voltage vs temperature characteristic certainly will vary between different types of temperature sensors.

You will have to study the datasheet for the particular type of sensor you intend to use to determine the appropriate calculation to convert the voltage to temperature.

Also, the count returned by the microcontroller's ADC for a given voltage will vary depending on the ADC's voltage reference and number of bits - this also will afffect the required calculation.