PIC18f2550 dark activated light

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

pic18f2550 and ldr led
pic18f2550 and ldr led

Code

The code is written in mikroC pro for PIC


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

Links

5pcs PIC18F2550 MICROCHIP DIP-28 IC

50PCS GL5516 5516 Light Dependent Resistor LDR 5MM