Table of Contents
How temperature sensor is interfaced with PIC micro controller?
How temperature sensor is interfaced with PIC micro controller? Combining an analog temperature sensor LM35 with PIC microcontroller is very simple, the require thing is an analog-to-digital module (ADC) compatible with PIC microcontroller. This will show procedure to easily connect the LM35 sensor with the PIC16F887 microcontroller and manufacture a simple DIY thermometer. The compiler used in this project is mikroC PRO for PIC.
The LM35 temperature sensor is a small pin tool (VCC, OUT and GND) with output power that corresponds directly to the Centigrade temperature (analog device). As the output of the LM35 varies depending on the temperature we need an ADC module (Analog-to-Digital Converter) to measure this voltage. ADC module converts analog data into digital data. The PIC16F887 microcontroller has 1 ADC module with 10-bit resolution and 14 channels.
The output of the LM35 has an equal measurement + 10mV / ° C factor as follows:
If the output voltage = 10mV -> temperature = 1 ° C
If the output voltage = 100mV -> temperature = 10 ° C
If the output voltage = 200mV -> temperature = 20 ° C
If the output voltage = 370mV -> temperature = 37 ° C
and so on.
- PIC16F887 microcontroller
- LM35 temperature sensor – datasheet
- 1602 LCD screen
- 10k ohm flexible resistor (or potentiometer)
- Bread board
- 5V voltage source
- Jumper threads
The relating project to this are as following
- Interfacing PIC16F887 with LM35 temperature sensor – CCS C
- LM335 interface connector with PIC16F887 MCU – MikroC Projects
Interfacing PIC microcontroller with LM35 sensor region:
For example a circuit diagram is shown below.
(All ground terminals are linked)
The LM35 has 3 anchors (from left to right):
Pin 1: VCC, connected to +5V
Pin 2: analog output, connected to RA0 / AN0
Pin 3: GND (ground), connected to circuit ground (0V)
The LM335 sensor output pin is connected to the RA0 / AN0 pin (analog pin 0) of PIC16F887.
The LCD module is connected to the PORTD pins by:
RS -> RD0
E -> RD1
D4 -> RD2
D5 -> RD3
D6 -> RD4
D7 -> RD5
In this example the PIC16F887 microcontroller operates with its internal oscillator (@ 8MHz) and the MCLR pin configured as a digital input pin (programmed in the software).
Working with PIC microcontroller with LM35 sensor mikroC code:
Studying the magnitude of the power using ADC gives us a number between 0 and 1023 (10-bit resolution), 0V represented by 0 and 5V represented by 1023. conversion:
Voltage (Volts) = ADC reads * 5/1023
Multiplying the previous output by 100 (LM35 scale is 10mV / ° C = 0.01V / ° C) will provide the actual temperature:
Temperature (° C) = ADC reads * 0.489
where 0.489 = 500/1023
The terms for the microC suspension are:
Connecting Temperature sensor with PIC
Transducers convert physical data such as temperature, light intensity, flow, and speed to electrical signals. Depending on the transducer, the output that is produced in the form of voltage, current, resistance, or capacitance. For example, temperature is converted to electrical signals using a transducer called a thermistor. A thermistor responds to temperature
change by changing resistance, but its response is not linear, as seen in Table 1.
The complexity associated with writing software for such non- linear devices has led many manufacturers to market a linear temperature sensor. Simple and widely used linear temperature sensors include the LM34 and LM35 series from National Semiconductor Corp. They are discussed next.
Table 1: Thermistor Resistance vs. Temperature
Temperature(C) Tf (K ohms)
From W’lliamKleitz, Digital Electronics
LM34 and LM35 temperature sensors
The sensors of the LM34 series are precision integrated-circuit temperature sensors whose output voltage is linearly proportional to the Fahrenheit temperature .Take a look to table 2.The LM34 requires no external calibration because it is internally calibrated. It outputs 10 mV for each degree of Fahrenheit temperature. Table 2 is a selection guide for the LM34.
Table 2: LM34 Temperature Sensor Series Selection Guide
|Part Scale||Temperature Range||Accuracy||Output|
|LM34A||—50 F to +300 F||+2.0 F||10 mV/F|
|LM34||—50 F to +300 F||+3.0 F||10 mV/F|
|LM34CA||—40 F to +230 F||+2.0 F||10 mV/F|
|LM34C||—40 F to +230 F||+3.0 F||10 mV/F|
|LM34D||—32 F to +212 F||+4.0 F||10 mV/F|
Note: Temperature range is in degrees Fahrenheit.
Table 3: LM35 Temperature sensor series selection guide
Part Temperature Range Accuracy Outpt Scale
LM35A -55 Cto+150C +1.0C l0mV/C
LM35 -55 Cto+150C +1.5C l0mV/
LM35CA -40 Cto+110C +l.0C 10mV/C
LM35C -40 Cto+110 C +1.5C 10mV/C
LM35D 0Cto+100C +2.0C 10mV/C
The LM35 series sensors are precision integrated-circuit temperature sensors whose output voltage is linearly proportional to the Celsius (centigrade) temperature. The LM35 requires no external calibration because it is internally calibrated .It outputs 10mV for each degree of centigrade temperature .Table 3 is the selection guide for the LM35.
Figure shows the pin configuration of the LM34/LM35 temperature sensor and the connection of the temperature sensor
Also read here