Reading a Light Dependent Resistor


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Getting There

    Thanks Melanie, your suggestion worked just fine all working now and giving values between 2 and 19 dependent on the light level. I expect you can also output the Hex or Binary value to the SLCD. Had a hunt around but couldn't figure how to do this.

    For Dave: After I posted last night did a bit of night time reading and was looking at the ADCIN section of the manual. However wasn't entirely comfortable with what they were talking about. However, you post was encouragement enough for me to give it a try.

    I used the code below (pretty much out of the manual). Then put the light dependent resistor from the Vdd to the RA0/AN0 pin. Before putting the resistor in the reading on the SLCD was all over the place. With the resistor in place it sits at 253 - 254. So I guess I have the right pin. However, If I reduce the light I see no change in the reading.

    I am using a PIC18F4620

    DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling

    tone var byte

    TRISA = 255 ' Set PORTA to all input
    ADCON1 = 0 ' PORTA is analog

    :start

    ADCIN 0, tone ' Read channel 0 to tone
    Serout 0, 6, [$fe, $1] ' Clear screen and move cursor to start of first line
    Serout 0, 6, [$1b, $52, 1, #tone] ' Output number value to SLCD.
    pause 500

    goto start

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    ADC is not to bad once you get the feel for it. Bruce has good examples at his site www.rentron.com.

    I do not have the data sheet for the chip you are using so I can not tell you how to set it up but it looks like your close.

    Things I would change are to use binary for ADCON1 and TRISA. For example
    Code:
    ADCON1 = %00010111
    TRISA = %11111111
    In the data sheet there should be a table for ADCON1 telling how the bits are to be set.
    Here is an example of the "old way" of doing it. Sometimes this works better than ADCIN. (more control I think).

    Let us know how it goes.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Update

    Yes I can see that ADC is definately the way to go. I had a bit of a go with what you suggested and made some headway however could not get totally predictable results. I think the PIC18F4620 is not the best one for me to use to get a good understanding of what is happening. It's datasheet is 130 pages long and it is a bit daunting for a beginner. For every question I research I seem to end up with another long list of questions.

    I am going to work through the examples on http://www.rentron.com using the PIC's and examples they have there. Hopefully, that will give me a good understanding of what is going on then I will try again with the PIC18F4620. Will keep you posted.

    Cheers Bruce

Similar Threads

  1. 12F629 LDR - Light Dependant Resistor
    By Dennis in forum Schematics
    Replies: 15
    Last Post: - 18th February 2010, 23:33
  2. A/D on 16F767 for light tracking.
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th November 2007, 06:56
  3. Reading A Photo Resistor using ADC
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2007, 10:28
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 23:19
  5. Replies: 5
    Last Post: - 2nd March 2006, 10:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts