Arduino TMP37 Centigrade Temperature Sensor Tutorial

by Lewis Loflin

  
  

Here we will learn how to connect a basic ATMEGA168/Arduino module to a Hd44780 based liquid crystal display and use this to display in Fahrenheit the output of an Analog Devices TMP37 temperature sensor.

To use an I2C LCD display see Arduino TMP37 I2C Temperature Display

TMP37 pin connections
TMP37 pin connections.

This illustration shows the wiring connection for the typical 2 line by 16 character display available off Ebay or any number of Arduino vendors. In addition a pre-written programming library is available to operate the display as wired above to simplify programming.



TMP37 Specifications and Pin Connections

The TMP37 is intended for applications over the range of 5 degrees C to 100 degrees C and provides an output scale factor of 20 mV per degrees C. The TMP37 provides a 500 mV output at 25 degrees C. Operation extends to 150 degrees C with reduced accuracy for all devices when operating from a 5 V supply.

The low output impedance of the TMP35/TMP36/TMP37 and its linear output and precise calibration simplify interfacing to temperature control circuitry and ADCs. All three devices are intended for single-supply operation from 2.7 V to 5.5 V maximum.

In my test a stable +5 volt supply must be used!

The supply current runs well below 50 uA, providing very low self-heating-less than 0.1 degrees C in still air. In addition, a shutdown function is provided to cut the supply current to less than 0.5 uA. For more information on the TMP37 download the specification sheet. (pdf format)

In this project pin 1 is connected to +5 volts, pin 2 to the analog 0 input on the Arduino module, and pin 3 to ground.

About the Program

An analog to digital converter (ADC) in the ATMEGA168 or ATMEGA328 are 10-bit (1024 steps) and over a range of 5 volts is 5.0/1024 = 4.882 mV per step. The TMP37 produces an output of 20 mV / degrees C. It's easy to see they don't divide equally. Using the original sample program that came with the part when I ordered worked, but was unstable to the extreme bouncing around as much as ten degrees.

So beside rewriting the code to work with a LCD display instead of a computer serial port, I had to deal with the fact we were using very small real numbers and the fact the hardware didn't exactly match. But accuracy came out within a few degrees with a good 5-volt supply.

This produced both a stable reading within 1.5 degrees of a laboratory analog thermometer. (I don't have digital version.)



Arduino Code

Arduino LCD Schematic Typical 2 line by 16 character LCD connection to a generic Arduino module. R1 is used to adjust LCD contrast, pins 15 and 16 are the back light.

/*
 LiquidCrystal Library 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. 
 */

// include the library code:
#include <LiquidCrystal.h>

char myString[10];

// initialize the library with 
// the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
}

void loop() {
  
    int sensorValue = analogRead(0);
    // convert ADC value to volts
    float volts = sensorValue * 5.0 / 1024 ;  
    // convert volts to Celsius 20mV per degree
    float Celsius = volts / .02 ; 
    // conversion from Celsius to Fahrenheit
    float Fahrenheit = (Celsius  * 9.0 / 5.0) + 32;
  lcd.home();
  lcd.print(Fahrenheit);
  lcd.print(" deg. F");
 // lcd.print("    ");
  delay(200);
}




You Tube Arduino Microcontroller Video Series March 2012: