TMP36 With Arduino Temperature Sensor Code & Tutorial

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

  1. Arduino TMP36 Temperature Sensor
  2. TMP36 Interfacing With Arduino
  3. TMP36 Arduino Code Example – Temperature Sensor
  4. Arduino TMP36 LCD Example (I2C LCD)
  5. Arduino Multiple TMP36 Temperature Sensors Example
  6. Wrap Up

Arduino TMP36 Temperature Sensor

tmp36

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 Pinout Diagram

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.

Arduino-TMP36-Sensor-output-equation

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
❕ Note

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.

Arduino-UNO-Pinout-Analog-Input-Pins-ADC

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.


0V
0

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.

???? Also Read
Arduino ADC analogRead Tutorial

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-Wiring-Diagram

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.


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.

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.

setup()

in the setup() function, we’ll initialize the UART serial port communication @ 9600bps baud rate.

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.

Then, we’ll just format the message string and send it over UART to be printed on the serial monitor at the PC side.

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

Here is a demo video for testing this project on my Arduino UNO board.


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.

???? Also Read
Arduino I2C LCD 16x2 Interfacing Tutorial & Library Examples

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.

Arduino-TMP36-LCD-16x2-I2C-Example

Code Example

Here is the complete code listing for this example project.

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.

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.

setup()

in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.

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.

Then, we’ll construct the string message that shows the resulting measured temperature and print it on the I2C LCD display.

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

Here is a demo video for testing this project on my Arduino UNO board.


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.

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.

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.

setup()

in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.

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.

We’ll do exactly the same logic to get the reading of the second TMP36 temperature sensor.

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.

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

Here is a demo video for testing this project on my Arduino UNO board.


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.

???? Also Read
Getting Started With Arduino Programming For Beginners

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.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment