Interfacing PIC16F877A with LM335 analog temperature sensor – CCS C

The LM335 temperature sensor is an analog device which requires an ADC module to convert the analog data which is the voltage output from the LM335 into digital data. The LM335 has the following features:

  • 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 is for example is 3.03 (3030 mV) that means the temperature is: 303 °Kelvin = 30 °Celsius.
This topic shows how to interface the LM335 temperature sensor with PIC16F877A microcontroller.

Hardware Required:

  • PIC16F877A microcontroller
  • LM335 Temperature sensor – datasheet
  • 16×2 LCD Screen
  • 8MHz crystal
  • 2 x 22pF ceramic capacitor
  • 10K ohm potentiometer or variable resistor
  • 2.2K ohm resistor
  • +5V Power supply source
  • Breadboard
  • Jumper wires

Interfacing PIC16F877A with LM335 temperature sensor circuit:

PIC16F877A LM335 temperature sensor interfacing circuit

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 (16×2) 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 PIC16F877A runs with 8MHz crystal oscillator.

Interfacing PIC16F877A with LM335 sensor CCS C Code:
The following C code was tested with CCS PIC C compiler version 5.051.

Interfacing PIC16F877A with LM335 sensor videos:
The following video shows a breadboard hardware circuit of the example.

and the second video shows simulation using Proteus software.

Discover more from Simple Circuit

Subscribe to get the latest posts to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

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

Scroll to Top