The concept of a dark activated light is quite simple, we use a light dependent resistor (LDR) to an ADC pin on our PIC micro, we then read in a value based on the amount of light on the LDR. Full light gives the maximum value and no light gives the minimum value, so we take a low value and if our ADC goes below this we switch on an LED, real world you would use a high brightness LED.
Schematics
Code
The code is written in mikroC pro for PIC
[c]
unsigned int adcvalue,light_res;
void main()
{
TRISB = 0x00;
do {
light_res = ADC_Read(0); // Get 10-bit results of AD conversion
adcvalue = light_res;
if(adcvalue < 200)
{
PORTB = 0x01;
}
else
{
PORTB = 0x00;
}
Delay_ms(300);
} while(1);
} // end main
[/c]
Links