lm35 Using Atmega8
lm35 Using Atmega8
lm35 Using Atmega8
Submitted by,
NAME USN
NANDAN.M [1DS16CS067]
MOHAN [1DS16CS059]
MURALI [1DS16CS063]
CONTENTS
1. INTRODUCTION
2. HARDWARE REWQUIREMENTS
2.1. LM35 TEMPERATURE SENSOR
2.2. ATMEGA 8 MICROCONTROLLER
2.3. ISP PROGRAMMER
2.4. SEVEN SEGMENT DISPLAY MODULE
3. CIRCUIT DIAGRAM
4. ALGORITHM AND IMPLEMENTATION
5. SNAPSHOTS
6. FUTURE ENHANCEMENTS
INTRODUCTION
In this project, we are measuring the temperature using the LM35 temperature
sensor and display on the two seven segment. The LM35 sensor can measure
the temperature from full −55° to +150°C range. For display the temperature up
to +150°C we need three seven segment display. But in this project, to make
project simple and easy to understand we used only two segments.
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.
ATMEGA 8 MICROCONTROLLER
The abbreviation of AVR Microcontroller is “Advanced Virtual RISC” and
MCU is the short term of the Microcontroller. The Microcontroller includes the
Harvard architecture that works rapidly with the RISC. The features of this
Microcontroller include different features compared with other like sleep
modes-6, inbuilt ADC (analog to digital converter), internal oscillator and serial
data communication, performs the instructions in a single execution cycle.
These Microcontroller were very fast and they utilize low power to work in
different power saving modes.
The main feature of Atmega8 Microcontroller is that, all the pins of the
Microcontroller support two signals except 5-pins. The Atmega8
microcontroller consists of 28 pins where pins 9,10,14,15,16,17,18,19 are used
for port B, Pins 23,24,25,26,27,28 and 1 are used for port C and pins
2,3,4,5,6,11,12 are used for port D.
ISP PROGRAMMER
In-system programming (ISP), also called in-circuit serial programming (ICSP),
is the ability of some programmable logic devices, microcontrollers, and other
embedded devices to be programmed while installed in a complete system,
rather than requiring the chip to be programmed prior to installing it into the
system.
Two seven segment displays are multiplexed and are connected to port D of the
microcontroller.
CIRCUIT DIAGRAM
ALGORITHM AND IMPLIMENTATION
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 1000000UL
#include <util/delay.h>
int count=0;
int d0,d1,seg;
int ReadADC(uint8_t ch)
{
ADMUX=ch;
//Start Single conversion
ADCSRA |= (1<<ADSC);
//Wait for conversion to complete
while(!(ADCSRA&(1<<ADIF)));
ADCSRA|=(1<<ADIF);
return(ADC);
}
void initADC()
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1);
}
void segment_code(int seg)
{
switch(seg)
{
case 1:
PORTD=0b11111001; //1
_delay_ms(5);
break;
case 2:
PORTD=0b10100100; //2
_delay_ms(5);
break;
case 3:
PORTD=0b10110000; //3
_delay_ms(5);
break;
case 4:
PORTD=0b10011001; //4
_delay_ms(5);
break;
case 5:
PORTD=0b10010010; //5
_delay_ms(5);
break;
case 6:
PORTD=0b10000010; //6
_delay_ms(5);
break;
case 7:
PORTD=0b11111000; //7
_delay_ms(5);
break;
case 8:
PORTD=0b10000000; //8
_delay_ms(5);
break;
case 9:
PORTD=0b10010000; //9
_delay_ms(5);
break;
case 0:
PORTD=0b11000000; //0
_delay_ms(5);
break;
}
}
int main()
{
DDRC=0b0000000;
DDRD=0xFF; // PORT D as output port
DDRB=0xFF; //PB0 and PB1 is segment select pins
initADC();
int analogVal,i;
PORTB=0b11111101;
PORTD=0b00000000;
_delay_ms(5000);
PORTB=0b11111110;
PORTD=0b00000000;
_delay_ms(5000);
while(1)
{
analogVal=ReadADC(0);
analogVal=analogVal/2;
count=analogVal;
//variable do containing the 10th digit of
temperature
for(i=1;i<=20;i++)
{
d0=count%10;
seg=d0;
PORTB=0b11111101;//select segment 0
segment_code(seg);//match and display
//get the 100th digit of temperature
d1=count/10;
d1=d1%10;
seg=d1;
PORTB=0b11111110;//select segment 1
segment_code(seg);//match and display
}
}
return 0;
}
SNAPSHOTS
FUTURE ENHANCEMENTS
Temperature sensors are used just about everywhere. There are in the homes we
live in, the cars we drive, the schools we learn in. They are even in planes, trains
and boats. You will also find them in all sorts of electrical appliances and
electronic devices. Refrigerators, stoves, hot water tanks as well as computers,
GPS devices and battery chargers all have temperature sensors.
Considering the ease of development and low cost of the part the variety of
applications increase vastly. The domain of projects into which this project can
be enhanced to is quite large.