PIC12F1822 + 1602 LCD + LM335 Temperature Sensor

the LM335 is a 3-pin analog device which can measure temperature (converts temperature to analog voltage). This sensor requires an ADC to convert the analog data into digital data.
This topic shows how to build a thermometer using PIC12F1822 microcontroller and LM335 analog temperature sensor.

The LM335 sensor has the following features (from LM335 datasheet):

  • Directly Calibrated to the Kelvin Temperature Scale
  • 1°C Initial Accuracy Available
  • Operates from 400 μA to 5 mA
  • Less than 1-Ω Dynamic Impedance
  • Easily Calibrated
  • Wide Operating Temperature Range
  • 200°C Overrange
  • Low Cost

The LM335 has a breakdown voltage directly proportional to absolute temperature at 10 mV/°K. For example if the LM335 output voltage is equal to 3.03 (3030 mV) that means the temperature is: 303 Kelvin = 30 °Celsius.

The PIC12F1822 is an 8-bit microcontroller which has 4 analog channels with 10-bit resolution. The good thing with this microcontroller is the fixed voltage reference. With the fixed voltage reference we get approximately an exact result. Normally negative and positive references of the ADC module are VSS and VDD, but VDD is not exactly equal to 5.00V and here we should use the fixed voltage reference as a positive reference of the ADC module.

The PIC12F1822 has 3 fixed voltage references: 1.024V, 2.048V and 4.096V. For example if we set the fixed voltage reference to 4.096V and the ADC module is configured so that the negative and the positive references are VSS and FVR (Fixed Voltage Reference) respectively, in this case the equivalent 10-bit digital value of 4.096 is 1023 and 3.00V is 3.00 * 1023/4.096 = 749 , and so on.
In this project I used 4.096 because the LM335 output is between 2.23V (temperature = -50°C) and 3.98V (temperature = +125°C).

The temperature values (Kelvin and degree Celsius) are displayed on 1602 LCD display. This LCD is interfaced with the microcontroller using 74HC595 (74HC164 …..) shift register as what was done in this post:
Interfacing PIC12F1822 microcontroller with LCD display

Hardware Required:

  • PIC12F1822 microcontroller
  • LM335 Temperature sensor – datasheet
  • 1602 LCD Screen
  • 74HC595 shift register
  • 10K ohm variable resistor
  • 2.2K ohm resistor
  • +5V Power supply source
  • Breadboard
  • Jumper wires

Interfacing PIC12F1822 with LM335 temperature sensor circuit:

PIC12F1822 LM335 temperature sensor

The LM335 sensor has 3 pins (from left to right):
Pin 1 for calibration, not used in this example
Pin 2: output
Pin 3: GND (ground).
The output pin of the LM335 sensor is connected to analog channel 0 (RA0). I chose the 2.2K ohm because as written in the datasheet for optimum accuracy the current flows through the LM335 should be 1mA. For example if the temperature = 27°C, the output will be 3.00V and assume the supply voltage is exactly 5.00V that means the current flows through the sensor is ( 5 – 3)/2.2 = 0.90mA which is good enough. Also the value 2.2K is a standard value and well used.

The 1602 LCD display pins are connected to 74HC595 shift register except the Enable pin (E) which is connected directly to PIC12F1822. With the help of the shift register 74HC595 the LCD uses only 3 data lines: clock, data and enable. Other types of serial-in parallel-out shift registers can be used such as 74HC164 and CD4094 (74HC4094).

In this example the PIC12F1822 MCU uses its internal oscillator and MCLR pin function is disabled.

Interfacing PIC12F1822 with LM335 temperature sensor C code:
This code was tested with CCS PIC C compiler version 5.051.
To compile the C code below, the serial LCD driver source file must be added to the project just by downloading the source file and putting it on the project folder. The download link of the serial LCD driver is in this post:
3-Wire LCD driver for CCS PIC C compiler
The complete C code is the one below.

The Result:

PIC12F1822 LM335 temperature sensor circuit

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.