In this program we use an LDR to read the light condition. The connection diagram of LDR as follow-


LDR is nothing but a register that vary with light condition. At low light resistance is high and at high light the resistance is low. Temperature sensor LM35 is a digital temperature whose Vout value change according to temperature. The sensor has reading +10mV/°C. Since our ADC has a resolution 5/1024=4.88mV so the desire temperature is

The main program-
#include<avr/io.h>
#include<stdio.h>
#include<util/delay.h>
#include"adc.h"
#include"lcd.h"
uint16_t value,tempa;
float temperature;
char str[20];
int main(void)
{
LCD_INIT();
adc_init();
LCD_Clear();
DDRB|=(1<<DDB1); //LOAD PORT
_delay_ms(10);
LCD_Clear();
while(1)
{
value=read_adc(0);
tempa=read_adc(1);
temperature=(tempa*4.88)/10;
sprintf(str,"%d %.2f",value,temperature);
if(value<=400)
{
PORTB |=(1<<PINB1); //in dark condition glow
}else{
PORTB &=~(1<<PINB1); //else off
}
LCD_write_string(1,1,"ADC Temperature");
LCD_write_string(1,2,str);
}
return 0;
}
Read all dark condition of light and your desire condition inside if loop. For proper connection diagram see the proteus simulation.







Visit Today : 39
Total Visit : 28454