In this project, we are measuring the temperature using the LM35 temperature sensor and display the reading on the 16×2 LCD display. After reading the temperature, sensor gives the analog output to the AVR ATmega8 microcontroller.
This analog output from the sensor is sent to the ADC0 of the atmega8 that converts the analog data to the digital by inbuilt ADC in it.
The atmega8 has 6 ADC channel i.e. ADC0-ADC5. It means we can connect six analog sensors. The Port C and ADC pins are multiplexed to each other. The primary function of this pins is as an I/O and secondary is as ADC. To enable the ADC we need to enable it by setting the internal register of the atmega8 by writing the programming code.
The project consists two parts.
- LCD connection with atmega8
- LM35 interfacing with atmega8
Table of Contents
What is LM35 Temperature Sensor
The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius(Centigrade) temperature. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1⁄4°C at room temperature and ±3⁄4°C over a full −55 to +150°C temperature range.
- Calibrated directly in ° Celsius (Centigrade)
- Linear + 10.0 mV/°C scale factor
- 0.5°C accuracy guaranteeable (at +25°C)
- Rated for full −55° to +150°C range
- Suitable for remote applications
- Low cost due to wafer-level trimming
- Operates from 4 to 30 volts
- Less than 60 μA current drain
- Low self-heating, 0.08°C in still air
- Nonlinearity only ±1⁄4°C typical
- Low impedance output, 0.1 W for 1 mA load
More about LM35 Datasheet.
How to Calculate Analog to Digital Value – Formula
Use the following ratio:
e/V max = d/2 n– 1
- V max maximum voltage that the analog signal can assume
- n number of bits available for the digital encoding, Here n = 10
- d present digital encoding
- e present analog voltage from sensor
How to Calculate the Digital Value if we have 30 °C temperature.
scale factor = 10.0 mV/°C or 0.01V/°C
If we have 30 °C temperature than Voltage = 30 * 0.01 = 0.3V
So e = 0.30V
Vmax = 5V
d = e * 2 n– 1 / V max
d = 0.30 * 1023/5
d = 61.38 or almost double
Note: Every time we calculate the digital value, it is double to the temperature.
So in programming, we divide it by 2 for getting the approximate value of the temperature.
LM35 Temperature Sensor AVR ATmega8 Connection
LM35 Temperature Sensor AVR ATmega8 Code
int ReadADC(uint8_t ch)
ADCSRA |= (1<<ADSC);