In this tutorial I will measure the room temperature using the LM35 temperature sensor with 8051 microcontroller (89c51, 89c52). Lm35 outputs an analog signal that is proportional to the temperature in Celsius. The 89c51 microcontroller did not have an integrated analog to digital converter, unlike its relatives Arduino, PIC, NXP and STM32 microcontrollers. Therefore, we have to use an external analog to digital converter to measure the output voltage of the lm35, convert it to digital format, and pass it to the 89c51 microcontroller. I decided to use the adc0804 analog to digital converter to convert the analog voltage from the temperature sensor (LM35) into 8-bit digital value and pass it to the microcontroller whenever requested.
Ambient temperature monitoring project – working principle
The Lm35 temperature sensor will measure the ambient analog temperature and pass through the adc0408 for analog to digital conversion. The 89c51 microcontroller fetches the temperature value from the adc0804 analog to digital converter. The temperature value is then displayed on a 16×2 LCD interfaced with the 89c51 microcontroller. I am not only displaying the temperature value in Celsius on the 16×2 LCD, but also converting it to Fahrenheit and displaying the Fahrenheit temperature on the 16×2 LCD as well.
Analog room temperature measurement from Lm35 temperature sensor – Analog to digital conversion principle
The LM35 outputs voltage in Celsius. The LM35's 10 millivolt output represents 1 degree Celsius. So if the LM35 produces 90 mV, it means the temperature is 9 degrees Celsius.
If you are new and don't know much about how it works, pin the LM35 temperature sensor. Please follow the tutorial below. It is an introduction to the LM35 temperature sensor, its pinout and working principle. The tutorial will help you understand the code below.
LM35 pinout, operation and temperature calculation formula
Digital Thermometer with 8051 Microcontroller – Project Requirements
- 89c51 or 89c52 microcontroller (you can also use any other)
- ADC0804 (analog to digital converter)
- LM35 temperature sensor
- LCD 16×2
- power supply (5 volts)
- Bread board (to make a circuit)
- Crystal (11.0592 MHz)
If you are new and don't know about ADC0804 and 16×2 LCD. Below are some good tutorials.
- Pinout and operation of the ADC0804.
-
Pinout and operation of 16 × 2 LCD.
8051 Digital Temperature Monitor – Circuit Connections
Port 1 of the 89c52 microcontroller is connected to the data pins of the 16×2 LCD. Port 2 of 89c51 is connected to the data pins of ADC0804. 16×2 lcd enable pin is connected to port 3, pin 6. RS (register select) pin is connected to port 3, pin 5. RW (read write) pin is connected to port 3, pin 7. CS (chip select) pin for ADC0804 is connected to port 3, pin 0. RD (read) pin of ADC0804 is connected to port 3, pin 2. WR (write) pin of ADC0804 is connected to port 3, pin 1. The INTR (interrupt) pin of the ADC0804 is connected to port 3 pin 3 of the 89c51 microcontroller.
The LM35 temperature sensor has three legs, one for input voltage (5v), one is GND (ground) and the third is output voltage or temperature in Celsius. The LM35 provides a temperature change of 1 degree Celsius with every 10 mv increase in temperature. The Vref/2 pin is a very important pin. It is used to set the reference voltage for ADC0804. Apply 1.28 volts to this pin. This will cause the ADC0804 to increase value with every 10 mv increase in temperature. Now both the ADC0804 and LM35 have the same voltage settings.
Grounding LCD ground pin. Apply 5 volts to the LCD's VCC pin. Set the contrast on the LCD contrast pin, use the variable potentiometer/resistor to set the contrast. The CLK R and CLK IN pins of the ADC0804 are clock pins to which you connect an external clock with these pins. But the best way is to use the below given configuration of 10k resistor in parallel with 150pf capacitor, it will utilize its internal clock. If you want to use external connection and external clock for CLK IN pin and leave CLK R empty.
measuring room temperature with 89c51 microcontroller
Digital thermometer 89c51 – Project code
The code is complex. The lcdint function is initializing our lcd. The character will be displayed on the LCD in a 5×7 matrix and our cursor will be blinking. The lcdcmd function selects the LCD command register and sends commands to the LCD command register. The display function selects the data record from the LCD and sends the data to the LCD. The farenheit function converts Celsius temperature to Fahrenheit and then displays the temperature on the LCD.
The above code is a little difficult and complex to understand. But if you followed the recommended tutorial links given above in the post, you can easily understand the circuit working, code flow, and each code instruction. Other tutorials on working with the Lm35 temperature sensor and measuring temperature are below. Each tutorial is about interfacing the Lm35 with different microcontrollers and measuring temperature.
Temperature measurement with Lm35 and Nodemcu microcontroller via WiFi
Download project files and code (C and HEX) written in C language and compiled using keil u vision 4. Project video is also provided with output. Please give us your feedback on the post. If you have any questions, write them below in the comments section.
Temperature with files/code 89c51