LM335 Sensor interface with PIC16F887 MCU – mikroC Projects

This small post shows how to measure the ambient temperature using LM335 analog temperature sensor and Microchip PIC16F887 microcontroller using mikroC Pro for PIC compiler from MikroElektronika.

Related Projects:
Interfacing PIC16F887 with LM335 temperature sensor – CCS C compiler
Interfacing PIC MCU with DHT11 sensor – mikroC
DHT22 Sensor interface with PIC microcontroller – mikroC Projects

The LM335 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.

Hardware Required:

  • PIC16F887 microcontroller   —> datasheet
  • LM335 temperature sensor   —> datasheet
  • 16×2 LCD Screen
  • 10k ohm variable resistor (or potentiometer)
  • 2.2k ohm resistor
  • 5V Power supply source
  • Breadboard
  • Jumper wires
  • PIC MCU Programmer (PICkit 3, PICkit 4…)

LM335 Sensor interface with PIC16F887 MCU circuit:
Circuit schematic diagram is shown below.

PIC16F887 with LM335 mikroC circuit

(All grounded terminals are connected)

The LM335 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 RA0/AN0 pin (analog pin 0) of the PIC16F887.

The LCD module is connected to PORTD pins with:
RS —> RD0
E  —> RD1
D4 —> RD2
D5 —> RD3
D6 —> RD4
D7 —> RD5

In this example the PIC16F887 microcontroller runs with its internal oscillator (@ 8MHz) and MCLR pin is configured as digital input pin (configured in the software).

LM335 Sensor interface with PIC16F887 MCU mikroC code:
mikroC configuration words are:
CONFIG1 : 0x2CD4
CONFIG2 : 0x0700

The configuration words can be changed from: Project –> Edit Project …

The resolution of the ADC (Analog-to-Digital Converter) module of the PIC16F887 is 10 bits which means it converts the analog input voltage (between 0 and 5V) into a digital number between 0 and 1023 (0V —> 0 and 5V —> 1023). To return the digital value into its correspondent voltage we can just multiply that value by 5/1023.

Therefor to get the temperature in °K we have to multiply the digital value of the analog voltage (output of the LM335) by 0.489 ( 0.489 = 500/1023).

Proteus simulation of this project should give the same result as shown in the video below (the compiler used in the video is CCS C):

LM335 datasheet

Discover more from Simple Circuit

Subscribe to get the latest posts sent 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