
Using A TMP36 Temperature Sensor With Arduino
The TMP36 temperature sensor is an easy way to measure temperature using an Arduino! The sensor can measure a fairly wide range of temperature (-50°C to 125°C), is fairly precise (0.1°C resolution), and is very low cost, making it a popular choice. In this tutorial we will go over the basics of hooking the TMP36 up and writing some basic code to read the analog input it is connected to.
A Few Considerations:
Before we jump into getting this TMP36 temperature sensor hooked up there are a few points to consider:
• This sensor is not weatherproof, so it will need to be shielded from direct exposure to the elements.
How It Works:
Unlike a thermistor, the TMP36 does not have a temperature sensitive resistor. Instead this sensor uses the property of diodes; as a diode changes temperature the voltage changes with it at a known rate. The sensor measures the small change and outputs an analog voltage between 0 and 1.75VDC based on it. To get the temperature we just need to measure the output voltage and a little bit of math!
If you have any questions, or need further clarification please post in the comments section below; this way future users of this tutorial can see the questions and answers!
aurdino due convert voltage to temperature from ad8495 16bit and output 5mv/degree C. can anyone send me the code for this.
int sensePin = A0; //This is the Arduino Pin that will control Relay #1
I don’t think there is a relay on this project 😉
Good Catch – Copy/Paste strikes again!
Thank you so very much for your excellent illustrations, the pictures are very clear with no “blurryness” I had no problem whatsoever understanding exactly how to use a TMP36 to work with an Ardunio using your MOST EXCELLENT diagrams. Thank you so very much for all the time you put into this.
I am using a single Arduino board to hook up the temp sensor and a fan powered using a transistor from one of the digital I/Os. Whenever power is supplied to the fan, the temperature sensor sees a jump in temp (jump in voltage). Why is this occurring and how do I fix the problem? Thanks!
Looks like the readings are quite arbitrary.. Does anyone have the same issue?
I found online that a resistor (41.7K) should be connected on the TMP36 analog output pin.
Any comments?
Thanks,
Sp.
Personally – i wouldn’t rely on the TMP36 to be anything more than a rough approximation. It is an easy sensor for people to learn with but if you are concerned about what the temperature actually is, there are far better options. I am a fan of using thermistors and thermocouples – all of these IC based temp sensors tend to read warm due to the internal heating of the onboard circuitry.
HI! I’m having problems every time i run the program it comes up with minus temperatures plz help.
int sensePin = A0;
int sensorInput;
double temp;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorInput = analogRead(A0);
temp = (double)sensorInput / 1024;
temp = temp * 5;
temp = temp – 0.5;
temp = temp * 100;
Serial.print(“Current Temperature: “);
Serial.println(temp);
if(temp > 15){
digitalWrite(2, LOW);
}
if(temp < 15){
digitalWrite(2, HIGH);
}
}
I'm trying to make a motor turn when it is over a certain temperature for a fan but i cant get it to work
can we connect the sensor output to the input of digital pin instead analog
no… they are analog sensors
I’m working with a TMP with a range of -40 to 125. How do i find a new number to divide by instead of the 1024
1024 stays the same change this line:
temp = temp – 0.5; //Subtract the offset
to
temp = temp – 0.4; //Subtract the offset
When I ran it for the first time, I get approximately the correct temperature, but as I continued using an Uno with the sensor, the TMP36 started reading excessively high temperatures into 100 before the board itself shut off and could not be used for several hours. Would you recommend using something like a capacitor to prevent this from occurring? And if so, where does the capacitor fit on the circuit?
If for example the sensor reached a temperature of 50 degrees celcius, can we use the code made from the sensor to make a motor spin?
Found this piece if code to work much better:
tempAve=0;
for(int i = 0; i < 1000; i++){
sensorInput = analogRead(A0); //read the analog sensor and store it
temp = (double)sensorInput / 1024; //find percentage of input reading
temp = temp * 5; //multiply by 5V to get voltage
temp = temp – 0.5; //Subtract the offset
temp = temp * 100; //Convert to degrees
tempAve=tempAve+temp;
}
tempAve=tempAve / 1000;
// Print result
Serial.print("Current Temperature: ");
Serial.println(tempAve); //in again
yikes that is bad – so if the average temperature reading exceeds about (+/-)32.7 Celsius your code freezes
temp variable is repeated, logic will get confuse. I’m not a pro, please comment on this tweaks.
#define buzzer 2
int sensePin=A0;
int sensorInput;
double temp;
int tempvoltage;
int temppercent;
int tempcelcius;
void setup() {
Serial.begin(9600);
pinMode (buzzer, OUTPUT);
}
void loop() {
sensorInput=analogRead(A0);
temp=sensorInput/1024;
tempvoltage=temp*5;
temppercent=tempvoltage*0.95;
tempcelcius=temppercent*100;
if (tempcelcius>37.5){
digitalWrite(buzzer, HIGH);
}
else{
digitalWrite(buzzer, LOW);
}
}
The variable temp is simply being reused. Everything on the right side of the equal sign is done first, and then the variable “temp” is made to equal those results and carried to the next operation. Saves declaring a bunch of variables for one time use.
your if statements are wrong
how is the value from sensor lies between 20 to 358
what are these values?
I don’t know if you’ve figured this out by now, but your “if” statement is backwards. I assume you want the fan to come on above 15c. It should be like this:
if(temp > 15){
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}