In this tutorial, you will learn how to measure temperature and how to send that information to the Serial Monitor.
The TMP36 series are precision integrated-circuit temperature devices with an output voltage linearly proportional to the Centigrade temperature. TMP36 is a three-terminal linear temperature sensor. It can measure temperature from -40 degrees Celsius to +125 degrees Celsius. The voltage output of the TMP36 increases by 10mV per degree Celsius rise in temperature. TMP36 can be operated from a 5V supply and the stand-by current is less than 60uA.
How to measure Temperature
The TMP36 temperature sensor produces an analog voltage directly proportional to temperature with an output of 1 millivolt per 0.1°C (10 mV per degree). The sketch will convert the analogRead value into voltage and subtract the offset to be able to get the temperature.
You can use a power supply anywhere between 3.3V and 5V. In the example below we will use a 5V supply.
If you’re using a 5V Arduino and connecting the sensor directly into an Analog pin, you can use these formulas to turn the 10-bit analog reading into a temperature:
Voltage at pin = (reading from sensor) * 5 / 1024
This formula converts the number 0-1024 from the Sensor into 0-5 Volts.
If you’re using a 3.3V Arduino, you’ll want to use this:
Voltage at pin = (reading from sensor) * 3.3 / 1024
This formula converts the number 0-1024 from the sensor into 0-5V.
Then, to convert volts into degrees we will need the following formula:
Temperature = [(analog voltage in V) – 0.5] * 100
Materials you will need
Component | Number |
---|---|
Arduino Uno Rev3 | 1x |
Jumper Wires | 3x |
Breadboard 400 points | 1x |
TMP36 Sensor | 1x |
Breadboard Layout

BreadBoard Layout – The TMP36 Temperature sensor is quite easy to hook up. But beware, the middle pin is going to the analog pin. The side pins go either to the GND or 5V / 3.3V supply. Look closely at your sensor that you do not mix up the GND and 5V / 3.3V pin.
The Code
// TMP36 sensor sketch
int sensorPin = 0;
void setup() {
Serial.begin(9600); // Start Serial Communication
}
void loop() {
// read the analog signal from the sensor
int reading = analogRead(sensorPin);
// convert the reading into voltage
float voltage = reading * 5.0;
voltage /= 1024.0;
// print the reading to the Serial Monitor
Serial.print(voltage); Serial.println(" volts");
// Convert the 10 mV per defree with an offset of 500mV to degrees
float temperatureC = (voltage - 0.5) * 100;
// Print the Temperature
Serial.print(temperatureC); Serial.println(" degrees C");
// Convert the temperature into Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
// print Fahrenheit to the Serial Monitor
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000); // delay for 1 second.
}
Code Explanation
Declare variables and start Serial Communication
To use the TMP36 sensor you will need to define which analog pin is used.
int sensorPin = 0;
void setup() {
// Start Serial Communication
Serial.begin(9600);
}
Read the analog Signal
As explained above the sensor is sending millivolts to the Arduino. Before you transform these millivolts to degrees we need to read the sensor. This is done by analogRead and the value is printed to the Serial Monitor. Remember, the value that is printed is the received voltage of the Sensor.
// convert the reading into voltage float
voltage = reading * 5.0; voltage /= 1024.0;
// print the reading to the Serial Monitor
Serial.print(voltage);
Serial.println(" volts");
Convert into degrees
As explained above, we will are going to use a formula that converts the voltage into degrees./ Convert the 10 mV per defree with an offset of 500mV to degrees.
float temperatureC = (voltage - 0.5) * 100;
// Print the Temperature
Serial.print(temperatureC);
Serial.println(" degrees C");
Convert infor Fahrenheit
We also want to show the Fahrenheit.
// print Fahrenheit to the Serial Monitor
Serial.print(temperatureF);
Serial.println(" degrees F");
// delay for 1 second.
delay(1000);
Become a member
You just read a free post but there are 2 member-only posts that you don't currently have access to.
Subscribe for $14.99 monthly or $99.99 yearly.
Comments
Comments are for members only.
Please become a member or sign in to join the conversation!