Project 9 – Analog Sensor: Light detection using LDR

PROJECT 9

ANALOG SENSOR: LIGHT DETECTION USING LDR

Back to Project 8                                                                                                      Go to Project 10

A photoresistor or light dependent resistor (LDR) is a resistor whose resistance decreases with increasing incident light intensity. It can also be referred to as a photoconductor. In here, we going to do a simple connection of LDR and display the ADC and Voltage value on LCD.

———————————————————————————————————————————————————-

COMPONENTS NEEDED

———————————————————————————————————————————————————-

 16 x 2 LCD Display
  LIGHT DEPENDENT RESISTOR
  1K RESISTOR
  BREADBOARD
  JUMPER WIRES

———————————————————————————————————————————————————-

CONNECTION

———————————————————————————————————————————————————-

There are 2 ways of constructing the voltage divider which are LDR on top or LDR on bottom.

LDR ON TOP
Refer to the figure below, a total of 3 wires are used. The RED wire connects the LDR and VDDThe BLACK connects the resistor and GND. Lastly, the YELLOW wire connects the RA0 and the LCD and resistor. Please refer to this webpage for further details.

LDR ON BOTTOM
Refer to the figure below, a total of 3 wires are used. The BLACK wire connects between the LDR and VDD. The RED wire connects the resistor and GND. Lastly, YELLOW wire connects the RA0 and the LCD and resistor. Please refer to this webpage for further details.

———————————————————————————————————————————————————-

ADDITIONAL INFORMATION

———————————————————————————————————————————————————-
MEASURING RESISTANCE OF LDR
To measure the LDR resistance, just probe directly the +ve to one side of LDR and the -ve to the other side of LDR.

LDR VOUT MEASUREMENT

In this case, we give the Vin as 5V and resistor are 1K.

E.g-1: LDR on Top, Rtop = 10K
Vout = 1K x 5V
1K + 10K
= 0.45V

E.g-2: LDR on bottom, Rbottom= 10K
Vout = 10K x 5V
10K + 1K<
= 4.54V

———————————————————————————————————————————————————-

CODE OVERVIEW

———————————————————————————————————————————————————-

for (i=0 ; i<10 ; i++)
{
adc_value = adc_value + ui_adc_read();
}
Read and store the ourput value of ADC for 10 times.

adc_value = adc_value/10;
Divide the adc_value by 10 times to get the average result.

volt_value = (adc_value*50)/102.4;
Same as project_4, to display the output in voltage, we need to recalculate the adc_value given and times with 50 and divided by 102.4.

Back to Project 8                                                                                                      Go to Project 10

———————————————————————————————————————————————————-

ATTACHMENT

1. P9 user manual.pdf
2. Project_9_code.zip

Buy

, , , ,

Related Post

Control and Monitor via SMS Part 2

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

PIC16F VS PIC18F:Analysis of PIC Mid-Range 8 bit family and Advanced 8-bits Family

Gesture Sensor (APDS9960) interface with SK40C+PIC16F877A

5 thoughts on “Project 9 – Analog Sensor: Light detection using LDR

  1. Hi, tonynwk88

    Would you mind to share more details of this LDR project with me? Is there a ‘project kit’ available for sale?

  2. for me it showing this error when i tried compiling. plz advice me

    Build C:\Users\HK\Desktop\Project_9\Project_9 for device 16F887
    Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

    Make: The target “C:\Users\HK\Desktop\Project_9\adc.p1” is out of date.
    Executing: “C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe” –pass1 C:\Users\HK\Desktop\Project_9\adc.c -q –chip=16F887 -P –runtime=default –opt=default -D__DEBUG=1 -g –asmlist “–errformat=Error [%n] %f; %l.%c %s” “–msgformat=Advisory[%n] %s” “–warnformat=Warning [%n] %f; %l.%c %s”

    Error [192] C:\Users\HK\Desktop\Project_9\adc.c; 117.1 undefined identifier “GODONE”

    Make: The target “C:\Users\HK\Desktop\Project_9\lcd.p1” is up to date.
    Make: The target “C:\Users\HK\Desktop\Project_9\Project_9.p1” is up to date.

    ********** Build failed! **********

  3. hari25,
    Try use GO_DONE instead of GODONE.
    The causes is from different version of Hi Tech C Compiler.
    If you still experience the same problem pls discuss in our technical forum.

  4. hello
    the code has been compiled successfully , but the voltage is not changing . its fixed .

Leave a Reply

Your email address will not be published. Required fields are marked *