Search the web
Sign In
New User? Sign Up
booksbybibin
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
atmega8L avr with temp sensor   Message List  
Reply | Forward Message #1763 of 1866 |

Hi,

I am doing my first avr exp using a temp sensor LM35 to blink blue green or red led according to the temp of the room.

  • Connected the leds to PORT B of atmega8L uC and temp sensor to ADC 3 input.
  • Using internal oscillator 1MHz as clk, internal reference voltage of 2.56 as reference voltage in FREE RUNING MODE.
  • ADLAR = 0 i.e. right adjusted. 
  • Connected a 0.1uF decoupling capacitor at VREF pin as per datasheet, ¡°Internal 2.56V Voltage Reference with external capacitor at AREF pin¡±.
  • Using prolight leds 1W (for good intensity), transistor in saturation with Ic around 10mA.

According to what I hv understood with temp sensor 10.0 mV/¢ªC scale factor, output voltage of sensor is input voltage of ADC ¡¦...

                                                ADC = ( Vin * 1024 / Vref )

If room temp= 30¢ªC, Vin = 300mV = 0.3V, So ADC = (.3*1024/2.56)=120. So I hv divided the result by 4.

 

 

 

Fig b.png

 

 

Here is my code that I hv written in AVR Studio4

#include<avr\io.h>

#define F_CPU 1000000UL

#include <util/delay.h>

int main (void)

{

  unsigned int TEMP;

  ADMUX= (1<<REFS1)| (1<<REFS0)| (1<<MUX1)| (1<<MUX0);

  ADCSRA= (1<<ADEN)| (1<<ADFR);

  DDRB|=0xFF;

  while(1)

  {

    TEMP=ADCL+ADCH*256;           // ADCH is read only to update ADC data register, otherwise no need

     TEMP=TEMP/4;

     if(TEMP<=20) 

     PORTB=1<<PB1;                          //BLUE

    else if(TEMP>20&&TEMP<=28)

    PORTB=1<<PB0;                           //GREEN

    else if(TEMP>28&&TEMP<=35)

    PORTB=1<<PB3;                           //RED

   else

    PORTB= ((1<<PB1)| (1<<PB0)| (1<<PB3));

  }

}

 

But I don¡¯t know what the problem is; uC only blinks the led which satisfies the minimum criteria for temp i.e. blue. Even if I multiply the final TEMP variable by 10000 and keep min temp criteria for blue led to blink as less than 2¢ªC, then also only blue led blinks. It seems the uC is taking no voltage as input.

I hv checked that if I write (PORTB=1<<PB0), then green led blinks or (PORTB=1<<PB3), then red led blinks instead of (PORTB=1<<PB1)

 

I have connected output pin of sensor directly to uC, is there a problem in it or do I need to use more decoupling capacitors somewhere in the circuit.

 



Fri Jul 3, 2009 11:45 am

welkyb
Offline Offline
Send Email Send Email

Forward
Message #1763 of 1866 |
Expand Messages Author Sort by Date

Hi, I am doing my first avr exp using a temp sensor LM35 to blink blue green or red led according to the temp of the room. * Connected the leds to PORT B of...
welkyb
Offline Send Email
Jul 4, 2009
6:02 pm

Hi, Just a couple of points, 1) When you first start the ADC, DO A DUMMY READ as the first conversion is unreliable. 2) In order to start the ADC in free...
s.holder123@...
s.holder123...
Offline Send Email
Jul 6, 2009
5:18 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help