This program reads the ambient temperature using an LM35 sensor connected to the ATmega32A microcontroller and displays it on a 16x2 LCD. The LM35 Temperature sensor outputs an analog signal, which is fed into the analog input pin PA0 (ADC channel 0) of the ATmega32A. Below is the schematic showing the connections for the LCD, LM35 temperature sensor, and necessary circuitry for the ATmega32A.
This tutorial provides the wiring diagram and programming code for setting up the temperature sensor with ATmega32 and an LCD. For hands-on implementation on a breadboard, refer to the LM35 Temperature Sensor with ATmega32 and LCD tutorial.
The program consists of several parts. The main code is in main.c
, with additional files adc.c
and adc.h
for the ADC module and lcd.c
and lcd.h
for the LCD. In this setup, we use the polling method to read temperature data from the ADC module.
Here is the main.c
code:
Below is the code for the LCD module (lcd.c
and lcd.h
):
lcd.c
lcd.h
The ADC module code (adc.c
and adc.h
) is as follows:
adc.c
adc.h
Program Overview
The program reads the ADC value from PA0 (ADC channel 0), which provides a 10-bit value (0-1023). By multiplying this ADC value by 4.88 and dividing by 10, it converts it to Celsius, then further to Fahrenheit. Using dtostrf()
, these temperature values are formatted as strings and displayed on the LCD. The LCD and ADC functions are organized in separate header files for modularity.