banner bristolwatch.com
Arduino connected to LCD display
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.

Arduino with a TMP37 Centigrade Temperature Sensor

by Lewis Loflin

The Arduino series of micro-controllers are outstanding and a dream come true for experimenter, hobbyist and professionals. Unlike the overpriced Parallax "Basic Stamp" or the various "PIC' series of micro-controllers Arduino offers low price, ease of use, and totally open source software. (The others don't, so one can get into copyright issues.)

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 and Celsius the output of an Analog Devices TMP37 temperature sensor.

The illustration above 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 pin connections
TMP37 pin connections.

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/ 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 maxi- mum.



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. The answer was to read the ADC 400 times and use an average.

This produced both a stable reading within 1.5 degrees of a laboratory analog thermometer. (I don't have digital version.) This can be calibrated against this thermometer by instead of dividing by 400 simply adjust the value of the variable 'scalar_value'. In my case I used a value of 435.





/*
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi Hd44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 The TMP37 temperature sensor is connected to Analog input 0
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD R/W to GND
 * LCD E pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * 10K pot for contrast:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 */


 
// include the library code:
#include "LiquidCrystal.h"

float voltsPerDegree = 0.02; // change to 0.01 for TMP35 & 36

    int sensorValue;
    float volts = 5.0 / 1024; // volts per step on ADC
    float Celsius;
    float Fahrenheit;
    float temp = 0;
    int scalar_value = 400;

// 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);  // 16 char by 2 lines
  lcd.noCursor(); // Hides the LCD cursor.
}

void loop() {

  // read/add analogRead(0) 400 times
  for (int i=0; i=400; i++)  {
    delay(1);
    temp = temp + analogRead(0);
  } 
  
    // calculate average, change 'scalar_value for accuracy
    sensorValue = temp/scalar_values;
    
    Celsius = (sensorValue * volts) / voltsPerDegree;
    // set the cursor to column 0, line 0
    lcd.setCursor(0, 0);
    lcd.print(Celsius);
    lcd.print(" degrees C ");
    
    Fahrenheit = (((sensorValue * volts) / voltsPerDegree)  * 9.0 / 5.0) + 32;
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    lcd.print(Fahrenheit); 
    lcd.print(" degrees F ");
    
    temp = 0; // clear temp;
    
}  // end loop



You Tube Arduino Microcontroller Video Series March 2012: