Wednesday, August 12, 2015

ARTICLE #2 - TMP36 Temperature Sensor with Arduino



Introduction :



TMP36 sensor

A temperature sensor, as its name indicates, is a chip that is used to measure the temperature of its surrounding environment.

Temperature sensors are used in multiple applications that require accurate temperature measurements such as weather forecasting, food processing, medical devices, also in automotive industry and many other fields.

The sensor that I will be using in this project is the TMP36 sensor from Analog Devices. It's an electrical sensor that, when it is connected to a microcontroller, converts data concerning temperature that it gathers from its surrounding environment to an electrical signal on its output that can be used by the microcontroller in the different computations that it performs.



TMP36 Sensor :



From the datasheet we can read that :

The TMP35/TMP36/TMP37 are low voltage, precision centigrade temperature sensors. They provide a voltage output that is linearly proportional to the Celsius (centigrade) temperature. The TMP35/ TMP36/TMP37 do not require any external calibration to provide typical accuracies of ±1°C at +25°C and ±2°C over the −40°C to +125°C temperature range.

The TMP36 features are :

TMP36 pin-out
  • Low Voltage Operation (+2.7 V to+5.5 V)
  • Calibrated Directly in °C
  • 10 mV/8°C Scale Factor 
  • ±2°C Accuracy OverTemperature 
  • ±0.5°C Linearity 
  • Stable with Large Capacitive Loads
  • Specified -40 °C to +125 °C, Operation to +150 °C
  • Less than 50 µA Quiescent Current
  • Shutdown Current 0.5 µA max


You can find more specifications here : datasheet


How temperature is measured ?

The most relevant characteristic of the TMP36 sensor is the relation between the temperature sensed and the voltage measured on its output pin.


The image below shows the plot of the output voltage as  a function of temperature.




The equation of this linear function is :

               Voltage = 0.01*Temperature + 0.5

The temperature as a function of voltage becomes : 

               Temperature = (Voltage - 0.5)*100  

So, for example if the voltage measured at the TMP36 output pin is 1V that means that the temperature is (1 - 0.5)*100 = 50 °C




Circuit wiring :

Project Parts :

The parts that you will need in this project are the following :
  • 1 breadboard.
  • 1 Arduino Uno.
  • 1 TMP36 sensor.
  • 5 jumper wires.

TMP36 Pin Description:

There are 3 pins on the TMP36 sensor, when seen from the front side they're wired as the following :
  • The left pin is connected to the 5 Volts pin of the Arduino Uno board.
  • The middle pin is the SIGNAL pin, it is connected to one of the Analog Input pins of the microcontroller.
  • The right pin is connected to the ground pin (GND).

Wiring:


The hardware wiring is very simple. The image below shows how the project's parts are wired together, the temperature sensor's pins are connected as described in the TMP36 pin description part.






Code :


This code example below shows how to configure a temperature sensor. The program also sets a serial communication with the computer to display the detected temperature on the serial monitor in the Arduino IDE.


//The SIGNAL pin of the TMP36 sensor named temperaturePin and connected to the analog pin 2  //of the Arduino board
int temperaturePin = 2;

void setup() {
  //This function of the Arduino Serial library starts the serial connection with the          //computer. 9600 is the Baud rate (9600 bits/sec)
  Serial.begin(9600);

}

void loop() {
  //creates the variables that we will be using
  float voltage, degreesC, pinValue;

  //stores the value that it has been read from temperature sensor
  pinValue = analogRead(temperaturePin);

  //Converts the pinValue to voltage
  voltage = pinValue*5/1024;

  //this formula converts the voltage to degrees Celsius
  degreesC = (voltage - 0.5) * 100.0;
  
  //these 2 functions are used to print data to the serial monitor of the computer
  Serial.print("deg C: ");
  Serial.println(degreesC);
  
  delay(1000);

}

After that you execute this program, open the serial monitor in the Arduino IDE.
You should be able to see the current temperature starting to be printed inthe serial monitor every 1 second like this :


deg C: 20.82 deg C: 21.78 deg C: 21.78 deg C: 23.73 deg C: 23.98 deg C: 25.68 deg C: 27.30 deg C: 31.05

No comments:

Post a Comment