Temprature Sensor TMP36

Hi Guys!

I recently had some issues using a TMP36 temperature sensor chip as it was my first time using one, and I'd like to share how I made it work so others can benefit. My aim was to set a variable to the current temperature in degrees 'C based on the sensors output. Below I've made a diagram of the sensor showing the pin connections (GND = Arduino Ground Pin, VOut = Arduino Analogue Pin, VIn = Arduino 5V Pin):

Connect the temperature sensor to your Arduino board using the following wiring diagram. I used an Arduino Uno for this project, however it should work with any Arduino board which supports 5V power and has an analogue-input:

Now connect the Arduino to the computer and open the IDE. I have made the following code to use with this sensor which you're welcome to copy and experiment with:

Once the code has compiled and uploaded to your board, open the Arduino serial monitor to see the results as shown below:

I hope it works well for everyone! These sensors are great but bare in mind the manufacturer states the sensors accuracy is +/- 2'C so it's not perfect Enjoy! :slight_smile:

Better to read a voltage-output sensor, like the TMP36, with 1.1volt Aref.
Then temp readout is independent of the 5volt supply of the Arduino (e.g. USB fluctuations).
With 1.1volt Aref, you also get a ~5x higher resolution (readout to 0.1C).
Downside of 1.1volt Aref is a ~55C limit, but that shouldn't be a problem if the sensor is used for room/outside temps.
Averaging can improve temp stability further.
Try this sketch. It uses 1.1volt Aref and averaging.
Leo..

// TMP36 temp sensor output connected to analogue input A0, 3.3volt and ground

unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total += analogRead(A0); // add each value
  }
  tempC = total * 0.001632 - 50.0; // Calibrate temp by changing the last digit(s) of 0.001632
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1); // one decimal place
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}