Arduino Beginner’s Course Lesson 6– Reading Sensor Data – Temperature TMP36

You can download our e-book ‘Learn Arduino’ from this link

During this lesson, we will go through the process of reading sensor data, the TMP36 temperature sensor to be precise. First lets describe the sensor in  more detail. The TMP36 (ebay) has a linear voltage to temperature output meaning there is no error correction to be calculated from our end, the sensor handles it brilliantly on its own. The following are some details taken directly from the datasheet:

  • Size: TO-92 package (3leads)
  • Price:  around and under $1.00
  • Temperature range: -40°C to 150°C
  • Output range: 0.1V (-40°C) to 2.0V (150°C)
  • Power: 2.7V to 5.5V , 0.05 mA current

The sensor is accurate up to around 125°C, beyond that increasing error margins are to be expected.

It has 3 leads

  • Pin 1 – Vin (+2.7V – +5.5V)
  • Pin 2 – Analog Voltage Output
  • Pin 3 Ground



Lets get started with connecting the sensor to our Arduino. Connect Pin 1 to +5V on the Arduino, Pin 3 to Arduino GND and Pin 2 to A0 on your Arduino.

Thats all, now how are we going to read temperature through an analog pin? So the sensor wil output a voltage of 10mV per centigrade starting at 500mV offset to allow for sub Zero temperatures. Having said that, we know we need to convert the analog reading on the Arduino (0-1023) to mV. Using the below formula we can achieve this with ease.

result in mV = (A0 reading)*(5000/1023)

The 5000 refers to the maximum the Arduino analog pin can read. So when using 3.3V Arduino like the Pro Mini, replace the 5000 with 3300. Now all that’s left is to convert mV to centigrade.

centigrade = (result in mV – 500)/10

And there you go… the result in centigrade.

Sample Code

int sensor = A0;

void setup() {


void loop(){
 //reading from the sensor
 int reading = analogRead(sensor);  
 // converting sensor reading to milli volts
 float reading_mV = reading * 5.0; //if using 3.3v replace the 5.0 with 3.3
 reading_mV /= 1024.0; 

 // convert mV to temperature 
 float temp = (reading_mV - 0.5) * 100;
 //print the temperature



Leave a Reply

Your email address will not be published. Required fields are marked *