Arduino — TMP36 Temperature Sensor
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.
About TMP36 Temperature Sensor
Pinout
TMP36 temperature sensor has three pins:
GND pin: needs to be connected to GND (0V)
VCC pin: needs to be connected to VCC (5V)
+Vs pin: is the power supply for the sensor which can vary between 2.7V to 5.5V.
Vout pin: signal pin gives the output voltage that is linearly proportional to the temperature, should be connected to a analog pin on Arduino.
How It Works
The TMP36 outputs the voltage linearly proportional to the Centigrade temperature. The output scale factor of the TMP36 is 10 mV/°C. It means that the temperature is calculated by dividing the voltage (mV) in output pin by 10.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
TMP36 analog temperature sensor with Arduino tutorial
In this tutorial, you will learn how to use a TMP36 analog temperature sensor with Arduino. I have included a wiring diagram and several example codes to help you get started!
In the first part of this article, you can find the specifications and information about the TMP35, TMP36, and TMP37 sensors. Next, we will look at how to connect the sensor to the Arduino.
The first code example can be used to take temperature readings from the sensor and display the results in the Serial Monitor. In the second example, I will show you how to display the temperature on an I2C LCD to create a standalone thermometer.
If you would like to learn more about other temperature sensors, check out the articles below.
Recommended articles
- The complete guide for DS18B20 digital temperature sensors with Arduino
- How to use DHT11 and DHT22 Sensors with Arduino
- LM35 analog temperature sensor with Arduino tutorial
- How to control a character I2C LCD with Arduino
- How to use a 16×2 character LCD with Arduino
Supplies
Hardware components
TMP36 analog temperature sensor (TO-92) | × 1 | Amazon |
Arduino Uno | × 1 | Amazon |
Breadboard | × 1 | Amazon |
Jumper wires | ~ 10 | Amazon |
16×2 character I2C LCD | × 1 | Amazon |
USB cable type A/B | × 1 | Amazon |
Software
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.
About the TMP35/TMP36/TMP37 analog temperature sensors
The TMP35/TMP36/TMP37 are low voltage, precision centigrade temperature sensors made by Analog Devices. They provide a voltage output that is linearly proportional to the temperature in degree Celsius (°C) and are, therefore, very easy to use with the Arduino. Moreover, they are precise, never wear out, and very inexpensive!
The TMP35/TMP36/TMP37 sensors do not require any external calibration to provide a typical accuracy of ±1°C at +25°C and ±2°C over the −40°C to +125°C temperature range.
The difference between the TMP35, TMP36, and TMP37 is their temperature operating range and output scale factor. The TMP35 reads temperatures from 10°C to 125°C and provides a 250 mV output at 25°C. This sensor is functionally compatible with the LM35 made by Texas Instruments. You can find a dedicated tutorial for the LM35 here:
The TMP36 reads temperatures from -40°C to 125°C, provides a 750mV output at 25°C, and operates to +125°C from a single 2.7 V supply. This sensor is functionally compatible with the LM50.
The TMP35 and TMP36 have the same output scale factor of 10 mV/°C.
The TMP37 is intended for an operating range of 5°C to 100°C and provides a 500 mV output at 25°C. This sensor provides a slightly higher precision than the other sensors and has an output scale factor of 20 mV/°C.
As you can see in the figure above, the output range of all of the sensors is between 0.1 V and 2 V. Note that the output voltage is independent of the supply voltage you use.
TMP35/TMP36/TMP37 pinout
The TMP35/TMP36/TMP37 sensors come in 3 different form factors, but the most common type is the 3-pin TO-92 package, which looks just like a transistor. The TMP36 version of this sensor has the model number TMP36GT9Z.
The pinout of the sensor is given in the figure below:
Note that pin 1 (+VS) is the leftmost pin when the flat side of the sensor (with the text printed on it) is facing towards you.
You can find more specifications of the TMP36 in the table below.
TMP36 analog temperature sensor specifications
Supply voltage | 2.7 V to 5.5 V |
Quiescent current | 50 µA |
Temperature range | -40°C to + 125°C |
Accuracy | ±1°C at +25°C ±2°C from -40°C to +125°C |
Output scale factor | 10 mV/°C |
Output voltage at 25°C | 750 mV |
Package | 3-pin TO-92 |
Manufacturer | Analog Devices |
Cost | Check price |
For more information, you can also check out the datasheet here:
Wiring – Connecting TMP36 temperature sensor to Arduino
Connecting a TMP36 to the Arduino is very easy as you only need to connect 3 pins. Start by connecting the +VS pin to the 5 V output of the Arduino and the GND pin to the ground. If you are using a 3.3 V Arduino, simply connect +VS to 3.3 V instead.
Next, connect the middle pin (VOUT) to any of the analog inputs of the Arduino. In this case, I used the analog input pin A0.
The connections are also given in the table below:
TMP36 analog temperature sensor connections
TMP36 | Arduino |
---|---|
Pin 1 (+VS) | 5 V |
Pin 2 (VOUT) | Pin A0 |
PIN 3 (GND) | GND |
To improve the stability of the sensor, the datasheet recommends adding a 0.1 μF ceramic capacitor between the +VS pin and GND. When you are using long cables, adding a small resistor (e.g. 750 Ω) in series with the signal line (VOUT) can also reduce the noise.
When I tested the sensor with an Arduino Uno, I got stable readings without the capacitor and resistor, but your results may vary.
Converting the TMP36 output voltage into temperature
To convert the output voltage of the sensor into the temperature in degree Celsius, you can use the following formula:
Temperature (°C) = (VOUT – 500) / 10
with VOUT in millivolt (mV). So if the output of the sensor is 750 mV, then the temperature is:
(750 – 500) / 10 = 25°C
As you can see in the wiring diagram above, the output of the TMP36 is connected to one of the analog inputs of the Arduino. The value of this analog input can be read with the function analogRead() as you will see in the code examples below. However, the function analogRead(pin) will not actually return the output voltage of the sensor.
Arduino boards contain a multichannel, 10-bit analog to digital converter (ADC), which will map input voltages between 0 and the operating voltage (5 V or 3.3 V) into integer values between 0 and 1023. On an Arduino Uno, for example, this yields a resolution between readings of 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit.
So if you use analogRead() to read the voltage at one of the analog inputs of the Arduino, you will get a value between 0 and 1023.
To convert this value back into the output voltage of the sensor, you can use:
VOUT = reading from ADC * (5000 / 1024)
And if you are using a 3.3 V Arduino:
VOUT = reading from ADC * (3300 / 1024)
We will use these formulas in the code examples below.
TMP36 analog temperature sensor with Arduino example code
With the following example code, you can read the temperature from a TMP36 sensor and display it in the Serial Monitor.
You can upload the example code to your Arduino using the Arduino IDE.
To copy the code, click on the button in the top right corner of the code field.
/* TMP36 analog temperature sensor with Arduino example code. More info: https://www.makerguides.com */ // Define to which pin of the Arduino the output of the TMP36 is connected: #define sensorPin A0 void setup() < // Begin serial communication at a baud rate of 9600: Serial.begin(9600); >void loop() < // Get a reading from the temperature sensor: int reading = analogRead(sensorPin); // Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in Celsius: float temperature = (voltage - 500) / 10; // Print the temperature in the Serial Monitor: Serial.print(temperature); Serial.print(" \xC2\xB0"); // shows degree symbol Serial.println("C"); delay(1000); // wait a second between readings >
You should see the following output in the Serial Monitor (Ctrl + Shift + M).
Make sure that the baud rate of the Serial Monitor is also set to 9600.
How the code works
First, I defined to which pin of the Arduino the VOUT pin of the sensor is connected. In this case, we used the analog pin A0. The statement #define can be used to give a name to a constant value. The compiler will replace all references to this constant with the defined value when the program is compiled. So everywhere you mention sensorPin , the compiler will replace it with A0 when the program is compiled.
// Define to which pin of the Arduino the output of the TMP36 is connected: #define sensorPin A0
In the setup section of the code, we begin serial communication at a baud rate of 9600.
void setup() < // Begin serial communication at a baud rate of 9600: Serial.begin(9600); >
In the loop section of the code, we start by taking a reading from the sensor with the function analogRead(pin) .
// Get a reading from the temperature sensor: int reading = analogRead(sensorPin);
Next, we use the formulas that I mentioned earlier in the article to convert the reading into voltage and then into temperature.
// Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = (voltage - 500) / 10;
If you are using a 3.3 V Arduino, like the Arduino Due or Arduino Nano 33 BLE, you need to connect the +VS pin to 3.3 V and replace the highlighted line with:
// Convert the reading into voltage: float voltage = reading * (3300 / 1024.0);
Lastly, the results are printed in the Serial Monitor:
// Print the temperature in the Serial Monitor: Serial.print(temperature); Serial.print(" \xC2\xB0"); // shows degree symbol Serial.println("C");
Display the TMP36 temperature readings on an I2C LCD
If you want to make a standalone thermometer that doesn’t need a computer, it can be nice to know how to display the temperature readings on an LCD display.
With the example code below, you can display the temperature readings on a 16×2 character I2C LCD.
Connecting the I2C LCD is fairly easy as you can see in the wiring diagram below. You can check out my detailed tutorial below for more information.
If you want to use a standard non-I2C LCD instead, take a look at this article:
- How to use a 16×2 character LCD with Arduino
The connections are also given in the table below:
I2C LCD Connections
I2C Character LCD | Arduino |
---|---|
GND | GND |
VCC | 5 V |
SDA | A4 |
SCL | A5 |
Note that the TMP36 temperature sensor is connected in the same way as before.
Installing the required Arduino libraries
To use an I2C LCD, you need to install the LiquidCrystal_I2C Arduino library.
To install this library, go to Tools > Manage Libraries (Ctrl + Shift + I on Windows) in the Arduino IDE. The Library Manager will open and update the list of installed libraries.
Now search for ‘liquidcrystal_i2c’ and look for the library by Frank de Brabander. Select the latest version and then click Install.
TMP36 with I2C LCD example code
/* TMP36 analog temperature sensor with I2C LCD and Arduino example code. More info: https://www.makerguides.com */ // Include the required Arduino libraries: #include// Create a new instance of the LiquidCrystal_I2C class: LiquidCrystal_I2C lcd(0x27, 16, 2); // Degree symbol: byte Degree[] = < B00111, B00101, B00111, B00000, B00000, B00000, B00000, B00000 >; // Define to which pin of the Arduino the TMP36 is connected: #define sensorPin A0 void setup() < // Start the LCD and turn on the backlight: lcd.init(); lcd.backlight(); // Create a custom character: lcd.createChar(0, Degree); >void loop() < // Get a reading from the temperature sensor: int reading = analogRead(sensorPin); // Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = (voltage - 500) / 10; // Print the temperature on the LCD; lcd.setCursor(0, 0); lcd.print("Temperature:"); lcd.setCursor(0, 1); lcd.print(temperature); lcd.write(0); // print the custom character lcd.print("C"); delay(1000); // wait a second between readings >
You should see the following output on the LCD:
Conclusion
In this tutorial, I have shown you how to use a TMP36 analog temperature sensor with Arduino. I hope you found it useful and informative. If you did, please share this article with a friend who also likes electronics and making things.
I would love to know what projects you plan on building (or have already built) with this sensor. If you have any questions, suggestions, or if you think that things are missing in this tutorial, please leave a comment below.
Note that comments are held for moderation to prevent spam.
Other Useful Links From Around The Web:
- Project Example with the I2C
- Another simple project example
- Circuit Geeks I2C LCD tutorial
- Micro Controllers Lab I2C LCD tutorial
- Useful YouTube Tutorial on the I2C LCD with Arduino
Аналоговый датчик температуры TMP36, Подключение к Arduino
Датчик температуры на выходе которого формируется напряжение пропорционально температуре по шкале Цельсия. Датчик функционально схож с LM35 но не является его полным аналогом.
Характеристики датчика:
- Диапазон температур: −40°C — +125°C
- Точность температуры: типичная, в диапазоне -40°C … +125°C, ±2°C , при температуре 25°C: ±1°C.
- Линейность: ±0.5°C.
- Разрешение: 10.0 mV/°C
- Напряжение на выходе при 25°C: 750мВ.
- Напряжение питания: 2,7В — 5,5В.
Купить:
Особенности работы с датчиком:
Как и у похожего аналогового датчика LM35, на выходе формируется напряжение пропорционально температуре по шкале Цельсия, величина напряжения также 10.0 mV на 1°C, но в отличии от LM35, где отсчет начинается от 0°C и при 25°C датчик формирует напряжение 250mV, TMP36 ведет отсчет от -50°C, а при 25°C на выходе датчика будет 750mV.
TMP36 лишен основного недостатка LM35 при совместном использовании с Arduino, невозможность измерения отрицательных температур, но недостатки все таки пристукивают. При использовании встроенного в микроконтроллер источника опорного напряжения 1,1 вольт, максимальная температура датчика ограниченна 60°C но это всё еще пригодно для домашних или уличных термометров.
Крайне не рекомендуется использовать в качестве опорного напряжения для АЦП, напряжение питания или напряжение от встроенного стабилизатора на 3,3 вольта, подключенное на вход AREF, стабильность тех напряжений крайне низкая, что будет негативно сказываться на точности показаний датчика. Правильным решением будет использование встроенного источника опорного, а если верхняя граница в 60°C не достаточна, либо внешний источник опорного, например MAX6125, либо использовать другой, более подходящий, датчик температуры.
Схема подключения датчика:
Софт:
Датчик не требует сторонних библиотек, код с использованием встроенного источника опорного ниже. Код актуален для плат на контроллере ATmega328.
/// истоки тут https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor #define sensorPin A0 // вход датчика void setup() Serial.begin(9600); // включаем встроенный источник опорного 1,1 вольт analogReference(INTERNAL); > void loop() //забераем данные с аналогового входа int reading = analogRead(sensorPin); // конвертируем в вольты с учетом встроенного источника опорного float voltage = (reading * 1.1) / 1024.0; // переводим в градусы float temperatureC = (voltage - 0.5) * 100 ; // отправляем в монитор порта Serial.print(voltage); Serial.println(" volts"); Serial.print(temperatureC); Serial.println(" degrees C"); delay(1000); //ждем секунду >
код из видео с двумя датчиками.
float tempC; int reading; void setup() analogReference(INTERNAL); // включаем внутрений источник опорного 1,1 вольт Serial.begin(9600); > void loop() // получаем значение с аналогового входа A0 int reading = analogRead(A0); float voltage = (reading * 1.1) / 1024.0; float temperatureC = (voltage - 0.5) * 100 ; tempC = analogRead(A1) / 9.31; // переводим в цельсии Serial.print(" LM35: "); Serial.print(tempC); // отправляем в монитор порта Serial.print(" TMP36: "); Serial.println(temperatureC); delay(1000); // ждем секунду >
Видео:
Читайте также:
- Подключение FM радиоприемника TEA5767 к Arduino
- Датчик температуры и влажности с RS485 на STM8.
- Датчик температуры и влажности HDC1080
- Датчик температуры и влажности HTU21D
- Датчик температуры и влажности с RS485
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
- 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.
- 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.
Temperature
25 °C
TMP36 Output Voltage
0.75 v
Expected ADC Reading
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 (2 n – 1) . Where VREF = 5v and n is the ADC resolution which is 10bits.
Resolution:
Vref:
Analog Input Voltage 0V
ADC Digital Value 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.
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.