In this tutorial, you’ll learn how to interface TMP36 With Arduino (Temperature Sensor) and use it to measure the surrounding temperature in degrees Celsius and Fahrenheit. We’ll create a couple of Arduino TMP36 code example projects to practice what we’ll learn in this tutorial.
And we’ll also interface Arduino with TMP36 and I2C LCD in this tutorial as well. Moreover, we’ll interface Multiple TMP36 Temperature Sensors With Arduino and display the temperature readings independently in another project within this tutorial. Without further ado, let’s jump right into it!
Table of Contents
- Arduino TMP36 Temperature Sensor
- TMP36 Interfacing With Arduino
- TMP36 Arduino Code Example – Temperature Sensor
- Arduino TMP36 LCD Example (I2C LCD)
- Arduino Multiple TMP36 Temperature Sensors Example
- Wrap Up
Arduino TMP36 Temperature Sensor
The TMP36 is a temperature sensor that is very easy to use in electronics projects and Arduino. The TMP36 sensor is rated to operate across a full range of −40°C to 125°C, thus making it suitable for a variety of temperature sensing applications.
You can power it up and instantly read the voltage level on the output terminal. The VOUT of the sensor directly maps to the sensor’s temperature (linear relationship) as we’ll see hereafter.
TMP36 Sensor Technical Specifications
- Operates From 2.7 V to 5.5 V
- Linear + 10-mV/°C Scale Factor
- ±0.5°C linearity
- ±2°C accuracy over temperature (typ)
- Rated for Full −40°C to 125°C Range, operates up to +150
- Less Than 50μA Current Drain
- VOUT range (0.1V at -40°C) To (1.75V at 125°C)
- VOUT at room temperature (25°C) is 0.75v
TMP36 Pinout
TMP36 V-T Characteristics
As stated in the TMP36 temperature sensor datasheet, the VOUT of the TMP36 sensor follows a simple linear function that’s shown below.
where VOUT is the TMP36 output voltage & T is the temperature in °C. And this is what we’ll be using in code in order to convert the ADC voltage readings to temperature values (in °C or °F).
You can play with the interactive tool below to see how the sensor’s analog output voltage changes when the temperature value is changed. And it’ll also show you the ADC digital value as captured (measured) by the Arduino code.
25 °C
0.75 v
128
At the maximum temperature (+125°C), the sensor’s output analog voltage will be almost 1.75v which is quite far from the Arduino’s ADC reference voltage (+5v). This means that most of the ADC’s range will stay unused and the voltage measurement resolution will be 5v/1024 = 5mv, which means we’ve got a temperature measurement resolution of 0.5°C.
The 0.5°C resolution is “luckily” higher than the sensor’s accuracy (which is ±2°C) so we don’t need to enhance the measurement resolution by changing the ADC’s VREF voltage to a lower value because the voltage resolution increase will not improve the overall measurement resolution due to the sensor’s characteristic accuracy itself.
Arduino ADC (Analog Input)
The Arduino UNO has 6 analog input pins labeled from A0 to A5 as shown in the figure below. Those pins can be used with analog peripherals in the Arduino microcontroller such as ADC (A/D Converter) and the Analog Comparator.
The Arduino ADC resolution is 10 bits, the digital output range is therefore from 0 up to 1023. And the analog input range is from 0v up to 5v (which is the default analog reference voltage VREF = +5v).
You can use the interactive tool below to set an analog input voltage and see the ADC digital output value that corresponds to the analog input voltage. The output equation for the ADC is as follows: ADC Output = ( Analog input voltage / VREF ) x (2n – 1). Where VREF = 5v and n is the ADC resolution which is 10bits.
It’s Highly Recommended to check out the tutorial below to learn more about Arduino ADC. It’s a prerequisite for this Arduino TMP36 temperature sensor interfacing tutorial to help you understand the topic in more detail.
This tutorial is the ultimate guide for Arduino ADC & reading analog input voltages using the analogRead() function. You’ll learn, in-depth, everything about Arduino ADC, how it works, and how to make the best use of it with a lot of tips and tricks all the way through.
TMP36 Interfacing With Arduino
The TMP36 sensor is a very popular temperature sensor that can easily be used with Arduino using the ADC analog input pin. It’s got a linear voltage output response with a slope of 10mv per °C and an offset voltage of 0.5v on the output pin. The typical TMP36 temperature sensor’s operating range is (-40°C To 125°C).
TMP36 Arduino Wiring (Circuit Diagram)
Here is the wiring diagram for Arduino with the TMP36 temperature sensor. Note that I’m using the A0 analog input pin to read the analog output voltage of the TMP36 temperature sensor.
TMP36 Arduino Code
Here is a test code example that reads the TMP36 temperature sensor’s output on the A0 analog input pin and prints the temperature value to the serial monitor over UART. You can use it to check that your wiring and connections are all okay.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* * LAB Name: Arduino TMP36 Temperature Sensor Interfacing * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #define TMP36_PIN A0 int TMP36_RawValue = 0; float Voltage_mV; float Temperature_C; float Temperature_F; void setup() { Serial.begin(9600); } void loop() { // Read TMP36 Sensor ADC Pin TMP36_RawValue = analogRead(TMP36_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature_C = Voltage_mV / 10; Temperature_F = (Temperature_C * 1.8) + 32; // Print The Readings Serial.print("Temperature = "); Serial.print(Temperature_C); Serial.print(" °C , "); Serial.print("Temperature = "); Serial.print(Temperature_F); Serial.println(" °F"); delay(100); } |
TMP36 Arduino Code Example – Temperature Sensor
In this example project, we’ll use Arduino analog input with a TMP36 temperature sensor to read the temperature value and print it over UART to the serial monitor in both units (degrees Celsius °C and Fahrenheit °F).
Code Example
Here is the complete code listing for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* * LAB Name: Arduino TMP36 Temperature Sensor Interfacing * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #define TMP36_PIN A0 int TMP36_RawValue = 0; float Voltage_mV; float Temperature_C; float Temperature_F; void setup() { Serial.begin(9600); } void loop() { // Read TMP36 Sensor ADC Pin TMP36_RawValue = analogRead(TMP36_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature_C = Voltage_mV / 10; Temperature_F = (Temperature_C * 1.8) + 32; // Print The Readings Serial.print("Temperature = "); Serial.print(Temperature_C); Serial.print(" °C , "); Serial.print("Temperature = "); Serial.print(Temperature_F); Serial.println(" °F"); delay(100); } |
Code Explanation
First, we define the IO pin used for the TMP36 temperature sensor’s analog voltage reading. And we’ll also define some variables to be used during the voltage-to-temperature conversion process.
1 2 3 4 5 6 |
#define TMP36_PIN A0 int TMP36_RawValue = 0; float Voltage_mV; float Temperature_C; float Temperature_F; |
setup()
in the setup() function, we’ll initialize the UART serial port communication @ 9600bps baud rate.
1 |
Serial.begin(9600); |
loop()
in the loop() function, we’ll call the analogRead() function to get the voltage reading of the TMP36 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in (°C and °F) units.
1 2 3 4 5 6 |
// Read TMP36_Sensor ADC Pin TMP36_RawValue = analogRead(TMP36_PIN); Voltage_mV = ((TMP36_RawValue*5.0)/1023.0) * 1000; // TempC = Voltage(mV) / 10 Temperature_C = Voltage_mV / 10; Temperature_F = (Temperature_C * 1.8) + 32; |
Then, we’ll just format the message string and send it over UART to be printed on the serial monitor at the PC side.
1 2 3 4 5 6 7 |
// Print The Readings Serial.print("Temperature = "); Serial.print(Temperature_C); Serial.print(" °C , "); Serial.print("Temperature = "); Serial.print(Temperature_F); Serial.println(" °F"); |
TinkerCAD Simulation
Here is the simulation result for this project on the TinkerCAD simulator. You can run it as is, or make a copy and add your own code and start running the simulation to see how it’s going to behave.
You can check this simulation project on TinkerCAD using this link.
Testing Results
Arduino TMP36 LCD Example (I2C LCD)
In this example project, we’ll use Arduino with a TMP36 temperature sensor and I2C LCD 16×2 display to print out the temperature measurement. This example project will use the I2C LCD 16×2 with Arduino which you can learn more about by checking the tutorial linked below.
This is the ultimate guide for Arduino I2C LCD 16×2 interfacing and library functions explanation. It’ll guide you through everything you’d need to interface Arduino with an I2C LCD display.
TMP36 Arduino I2C LCD Example Wiring
Here is how to wire up the circuit for this Arduino TMP36 + I2C LCD example project.
Code Example
Here is the complete code listing for this example project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* * LAB Name: Arduino TMP36 + I2C LCD 16x2 * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #include <Wire.h> #include <LiquidCrystal_I2C.h> #define TMP36_PIN A0 LiquidCrystal_I2C MyLCD(0x27, 16, 2); // Creates I2C LCD Object With (Address=0x27, Cols=16, Rows=2) int TMP36_RawValue = 0; float Voltage_mV; float Temperature_C; void setup() { MyLCD.init(); MyLCD.backlight(); MyLCD.setCursor(0, 0); } void loop() { // Read TMP36_Sensor ADC Pin TMP36_RawValue = analogRead(TMP36_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature_C = Voltage_mV / 10; // Print Temperature Reading To The I2C LCD MyLCD.clear(); MyLCD.print("Temperature:"); MyLCD.setCursor(0, 1); MyLCD.print(Temperature_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); delay(500); } |
Code Explanation
First of all, we should include the Wire.h library for I2C communication and the LiquidCrystal_I2C.h library for the I2C LCD control.
1 2 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> |
Then, we’ll define the analog input pin to be used for the TMP36 sensor reading, we’ll create an instance of the I2C_LCD class, and define some variables to be used in the voltage-to-temperature measurement & conversion process.
1 2 3 4 5 6 7 |
#define TMP36_PIN A0 LiquidCrystal_I2C MyLCD(0x27, 16, 2); // Creates I2C LCD Object With (Address=0x27, Cols=16, Rows=2) int TMP36_RawValue = 0; float Voltage_mV; float Temperature_C; |
setup()
in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.
1 2 3 |
MyLCD.init(); MyLCD.backlight(); MyLCD.setCursor(0, 0); |
loop()
in the loop() function, we’ll call the analogRead() function to get the voltage reading of the TMP36 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in the (°C) unit.
1 2 3 4 5 |
// Read TMP36_Sensor ADC Pin TMP36_RawValue = analogRead(TMP36_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature_C = Voltage_mV / 10; |
Then, we’ll construct the string message that shows the resulting measured temperature and print it on the I2C LCD display.
1 2 3 4 5 6 7 |
// Print Temperature Reading To The I2C LCD MyLCD.clear(); MyLCD.print("Temperature:"); MyLCD.setCursor(0, 1); MyLCD.print(Temperature_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); |
TinkerCAD Simulation
Here is the simulation result for this project on the TinkerCAD simulator. You can run it as is, or make a copy and add your own code and start running the simulation to see how it’s going to behave.
You can check this simulation project on TinkerCAD using this link.
Testing Results
Arduino Multiple TMP36 Temperature Sensors Example
In this example project, we’ll use multiple TMP36 temperature sensors with Arduino and I2C LCD display. We’ll take the temperature measurement from both sensors and display them separately on the I2C LCD display.
Code Example
Here is the complete code listing for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/* * LAB Name: Arduino Multiple TMP36 + I2C LCD 16x2 * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #include <Wire.h> #include <LiquidCrystal_I2C.h> #define TMP36_1_PIN A0 #define TMP36_2_PIN A1 LiquidCrystal_I2C MyLCD(0x27, 16, 2); // Creates I2C LCD Object With (Address=0x27, Cols=16, Rows=2) int TMP36_RawValue = 0; float Voltage_mV; float Temperature1_C; float Temperature2_C; void setup() { MyLCD.init(); MyLCD.backlight(); MyLCD.setCursor(0, 0); } void loop() { // Read TMP36 Sensor1 ADC Pin TMP36_RawValue = analogRead(TMP36_1_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature1_C = Voltage_mV / 10; // Read TMP36 Sensor2 ADC Pin TMP36_RawValue = analogRead(TMP36_2_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature2_C = Voltage_mV / 10; // Print Temperature Reading To The I2C LCD MyLCD.setCursor(0, 0); MyLCD.print("TMP36_1: "); MyLCD.print(Temperature1_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); MyLCD.setCursor(0, 1); MyLCD.print("TMP36_2: "); MyLCD.print(Temperature2_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); delay(100); } |
Code Explanation
First of all, we should include the Wire.h library for I2C communication and the LiquidCrystal_I2C.h library for the I2C LCD control.
1 2 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> |
Then, we’ll define the 2 analog input pins to be used for the two TMP36 sensors reading, we’ll create an instance of the I2C_LCD class, and define some variables to be used in the voltage-to-temperature measurement & conversion process.
1 2 3 4 5 6 7 8 9 |
#define TMP36_1_PIN A0 #define TMP36_2_PIN A1 LiquidCrystal_I2C MyLCD(0x27, 16, 2); // Creates I2C LCD Object With (Address=0x27, Cols=16, Rows=2) int TMP36_RawValue = 0; float Voltage_mV; float Temperature1_C; float Temperature2_C; |
setup()
in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.
1 2 3 |
MyLCD.init(); MyLCD.backlight(); MyLCD.setCursor(0, 0); |
loop()
in the loop() function, we’ll call the analogRead() function to get the voltage reading of the first TMP36 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in the (°C) unit.
1 2 3 4 5 |
// Read TMP36_Sensor1 ADC Pin TMP36_RawValue = analogRead(TMP36_1_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature1_C = Voltage_mV / 10; |
We’ll do exactly the same logic to get the reading of the second TMP36 temperature sensor.
1 2 3 4 5 |
// Read TMP36_Sensor2 ADC Pin TMP36_RawValue = analogRead(TMP36_2_PIN); Voltage_mV = (((TMP36_RawValue*5.0)/1023.0)-0.5) * 1000; // TempC = Voltage(mV) / 10 Temperature2_C = Voltage_mV / 10; |
Then, we’ll construct the string message that shows the resulting measured temperatures from TMP36 sensors 1 & 2. Then, we’ll print both temperature readings on the I2C LCD display.
1 2 3 4 5 6 7 8 9 10 11 |
// Print Temperature Reading To The I2C LCD MyLCD.setCursor(0, 0); MyLCD.print("TMP36_1: "); MyLCD.print(Temperature1_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); MyLCD.setCursor(0, 1); MyLCD.print("TMP36_2: "); MyLCD.print(Temperature2_C); MyLCD.print((char)223); // Show Degree Symbol (º) MyLCD.print("C"); |
TinkerCAD Simulation
Here is the simulation result for this project on the TinkerCAD simulator. You can run it as is, or make a copy and add your own code and start running the simulation to see how it’s going to behave.
You can check this simulation project on TinkerCAD using this link.
Testing Results
Parts List
Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.
Download Attachments
You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.
Wrap Up
To conclude this tutorial, we can say that you can easily interface Arduino with a TMP36 temperature sensor to read the surrounding temperature and use that information for various Arduino projects. You can build on top of the examples provided here in this tutorial to create so many applications, you’re only limited by your imagination. Let me know if you have further questions or need help implementing your project.
If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.
And follow this Arduino Series of Tutorials to learn more about Arduino Programming.
This is the ultimate guide for getting started with Arduino for beginners. It’ll help you learn the Arduino fundamentals for Hardware & Software and understand the basics required to accelerate your learning journey with Arduino Programming.