We will use the TMP36 from Analog Devices.
This can be direct purchased from the manufacturer for less than 50 cents in quantities of 1,000 pieces, or from retail sources for about $1.50. The TMP36 produces an analog voltage output with this functional characteristic:
where,
- t = temperature in °C (degrees Celsius),
- e = output in volts
The TMP36 has a worst case error of ±3 °C at 25 °C. Typically, it is much better than this. In any case, we can improve the accuracy of temperature measurements through a process of characterization and compensation. This is usually called calibration.
From Temperature to a Number and Back
An Analog-to-Digital converter (ADC) reads a voltage and converts it to a number. Our PIC micro-controller has an ADC built-in. With a 5-volt supply, the 10-bit ADC will yield an indication of 1 count per 0.5 degrees Celsius. At 25°C, the output of the TMP36 is 0.750 volts. The ADC compares this to a full-scale reference voltage, assume 5.0 volts. Thus the ADC output indication is:
For these functions to be useful, we need their inverses. After all, the temperature sensor produces a voltage which the ADC converts to a number. From this number we infer a temperature. The inverse function is:
which reduces to:
Precision Voltage Reference1
If we add the MCP1525, a precision 2.5-volt reference IC, attaching it to the Vref pin of the PIC16F690 we can improve our temperature measurements in 2 ways:
- line regulation of the IC guards against supply voltage changes (max 350 ppm).
- a lower reference voltage uses a larger portion of the available ADC range which increases temperature resolution.
Here is the function to convert ADC readings to temperature in degrees Celsius:
1 Since pin 18 is shared by Vref and ICSPCLK, you will need a switch or jumper to disconnect the output of the MCP1525 from the pin while you are burning new software into the μC.