PIC18F4550 + LM335 temperature sensor – CCS C

Interfacing PIC18F4550 with LM335 analog temperature sensor

As mentioned above, 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 one. this topic shows how to use PIC18F4550 microcontroller ADC module to measure the ambient temperature using the LM335 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 LM135 has a breakdown voltage directly proportional to absolute temperature at 10 mV/°K. If the LM335 output voltage for example is 3.03 (3030 mV) that means the temperature is: 303 °Kelvin = 30 °Celsius.

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 (AN0). 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 screen is connected to pins RD0~6. The 10K variable resistor is used to adjust the brightness of the screen.

In this example the PIC18F4550 runs with its internal oscillator @ 8MHz and MCLR pin function is disabled.