LM35 Temperature Sensor with ATmega32 and LCD

 In this tutorial, you will learn how to use LM35 temperature sensor with ATmega32 microcontroller. You will learn how to interface temperature sensor with ATmega32 and how to display the temperature on a LCD. Temperature will be shown in both, degree Celsius and in Fahrenheit. You will learn how to write code for temperature sensor with ATmega32 and LCD. The code is provided at the end. You will also see video demonstration.

Before you read the rest of the tutorial you might also be interested in our similar tutorials:

LCD Display of Temperature and Humidity using DHT11 & Arduino with Code

LM35 Temperature Sensor with Arduino and LCD

To demonstrate so that you know what to expect in this tutorial, below is picture of the interfacing of LM35, ATmega32 microcontroller, LCD on a breadboard.

LM35 temperature sensor ATmega32 LCD on breadboard

Circuit Diagram of Interfacing LM35, ATmega32 and LCD

The wiring diagram of connecting LM35 with ATmega32 microcontroller and 16x2 LCD is as shown below.

LM35 Temperature Sensor with ATmega32 and LCD


LM35 TO TransistorPackage
Fig: LM35 TO-Transistor Package

The LM35 temperature sensor is easy to interface with microcontroller. It can be directly connected to any of the ADC pin of the microcontroller without any additional external circuitry. It has three pins- the first is the positive terminal pin where 4V to 30V supply can be connected. Here we have connected to a +5V supply positive terminal. The second pin is the signal pin which is connected to the ADC0 or the pin 40 of the ATmega32 microcontroller. The third pin is the ground pin which is connected to the common ground.

The 16x2 LCD is connected to PORTD and we have used only 4 pins for the Data transfer. We have grounded the R/W pin. Thus only 6 pins for RS, E and 4 data lines have been used which are connected from PD2 to PD7 pins of the microcontroller.

Working Mechanism

The ATmega32 reads the temperature analog value using the ADC0(pin 40) and converts it to proper scale internally via software. The converted temperature value is then sent to the LCD.

Video Demonstration

Watch the following video to see how it works.


Programming ATmega32, LM35 temperature sensor and LCD

The C programming code for programming LM35 and LCD with ATmega32 is provided below. 

#ifndef F_CPU
#define FCPU 4000000UL

#include <avr/io.h>
#include <util/delay.h>

int main()

    char Ctemp[10], Ftemp[10];

	float c, f;

		c = (adcread(0)*4.88);
		c = (c/10.00);
        f = (c*9)/5 + 32;

		dtostrf(c, 6, 2, Ctemp);
		dtostrf(f, 5, 2, Ftemp);

   return 0;

The LCD code and the ADC code can be found in the following tutorials:

Reading and displaying temperature using ATmega32

Interrupt based Temperature Reading and Display with ATmega32

Post a Comment

Previous Post Next Post