LDR interfacing with pic microcontroller and mikro c
Welcome to MINA TECHNOLOGY.
In this tutorial we will learn how to interface LDR with PIC Microcontroller. Here I am use PIC16F877A Microcontroller and 5mm LDR. You can watch the video or read the written tutorial below.
LDR mean Light Dependent Resisor. It resistance depend on visible light. The LDR resistance Negative Co-efficient of Light. When visible light intensity is increase than the LDR resistance is decrease.
In this tutorial we will learn how to interface LDR with PIC Microcontroller. Here I am use PIC16F877A Microcontroller and 5mm LDR. You can watch the video or read the written tutorial below.
LDR mean Light Dependent Resisor. It resistance depend on visible light. The LDR resistance Negative Co-efficient of Light. When visible light intensity is increase than the LDR resistance is decrease.
Relation between resistance and light intersity |
LDR Resistance can be change (0.50 to 2.50)K.
In this project I am set 2.50K resistance for LDR.. Here I am use voltage divider circuit to provide MCU analog voltage.
voltage divider circuit of LDR |
Voltage Divider Rule:
Mikro C Code:
float adc_value;
float voltage;
void main() {
TRISA.F0 = 1; // RA0/AN0 is analog input
TRISB.F7 = 0; // RB7 is output
ADC_Init(); // Initialize adc module
while(1){
adc_value = Adc_Read(0); // RA0 Pin is analog input
voltage = (adc_value * 5 ) /1023;
if(voltage >= 1){
PORTB.F7 = 1;
}
else {
PORTB.F7 = 0;
}
delay_ms(100);
}
}
Click the download button for program file:
download |
No comments