12F629 LDR - Light Dependant Resistor


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1

    Default 12F629 LDR - Light Dependant Resistor

    Hi all

    I've been dabbling with an LDR and a PIC 12F629 (any PIC should work though) and found it so straight forward and simple that I thought some forum users might enjoy it and come up with some more interesting ideass.
    This really does add a whole new dimension to the traditional day/night sensor. You could start logging the amount of actual daylight etc.

    LDR's can be setup using either one of two very simple circuits.See this link for more info, I found it very helpful and interesting.
    http://www.doctronics.co.uk/ldr_sensors.htm

    Here is the code
    Code:
    *************************************************************************************
    '12f629 to demo the use of an LDR by DENNIS
    'see ldr test scehmatic
    'USES ONLY 1 PIC PIN
    '                +---+--+---+
    '            VCC 1   +--+   8 GND
    '    OSC1,X1,GP5 2          7 GP0,CIN+,PGD
    '    OSC2,X1,GP5 3          6 GP1,CIN-,PGC
    '  VPP,/MCLR,GP3 4          5 GP2,T0CKI,INT,COUT
    '                +----------+
    '                12Cxxx, 12Fxxx
    '
    ' I tested circuit in daylight and indoors, make sure you have enough light and dark separation
    ' Adjust the 10K potentiometer for the correct sensitivty
    ' For reverse operation just change IF GPIO.2 = 1 then dark << replace with 0
    ' This circuit does not require any crucuial timing and can be moved to any PIC 
    '************************************************************************************
    
            define OSC 4 '4MHz
            DEFINE OSCCAL_1K 1          ' Set OSCCAL for 1k -HELPS tuning the crystal for more accurate timing
            CMCON = 7                    'set digital mode
            'ansel = 0                   'GPIO.2 and GPIO.3 set as digital - disable if using 12629 for LDR
           'TRISIO = %76543210          ' port GPIO 0=output and 1=input
            TRISIO = %0000100          ' GPIO.2 is an input - all the rest are outputs
            
            
    ' Variables 
    LED var GPIO.0
    ' end of variables
            Start:
                If GPIO.2 = 1 then night
                HIGH led  'Turn on/off whatever you like by changing this line/replacing LED
                goto start 
            
            Night:
                Low led     'Turn off LED (or device)
                
                goto start
                END
    In my experiment I found the best light source to be real daylight, and walking around with the breadboard as I walked in and out the door the LED would switch off (in the dark- indoors) or on (outside in daylight).
    To alter the sensitivity the 10K pot can be adjusted, I found that halfway worked well.
    You can reverse the operation , in other words, off at night and on during the day by just changing the 1 in this line to a 0
    Code:
    If GPIO.2 = 1 then night
    The schematic is attached.

    Hope this helps someone, and post back any info about how it worked for you or what could be changed or added :-)

    Kind regards

    Dennis
    Attached Images Attached Images  

  2. #2


    Did you find this post helpful? Yes | No

    Default

    You don't really mean "-5V" in the schematic... call it "ground" or something... else we see the little gears in the IC come flying out...

    Mike Tripoli
    Last edited by mtripoli; - 15th February 2010 at 23:02. Reason: v

  3. #3


    Did you find this post helpful? Yes | No

    Default oooops!!

    Hehehe
    Speed kills hey ?
    Well that would make 10V the supply then :-) and without a regulator mmm could prove interesting ;-)

    Mike ..thanks a million for catching that one in time :-)
    Yes it definitely must be GND not -5v as in the schematic :-)
    Will see if I can replace the schematic :-0

    Keep well

    Kind regards
    Dennis

  4. #4


    Did you find this post helpful? Yes | No

    Default Please find the corrected schematic here

    Here it is .. the schematic corrected to show +5V and GND rails :-)

    Kind regards
    Dennis
    Attached Images Attached Images  

  5. #5
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Dennis,

    So you have an LDR and a pot and a 1 k resistor across the supply rails. Isn't this combination suppose to connect to an input on the micro? I mean how else is the micro suppose to sense a change then turn the LED on?
    Just an observation!

    BobK

    Nice program example though!
    Last edited by BobK; - 16th February 2010 at 03:36. Reason: After thought

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Wiper on POT to GPIO.2..?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Stairwell light code from BS1 to PHP2.50a
    By vtt-info in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st December 2007, 17:32
  2. A/D on 16F767 for light tracking.
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th November 2007, 05:56
  3. Reading a Light Dependent Resistor
    By kiwipiper in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st October 2007, 05:29
  4. Replies: 5
    Last Post: - 2nd March 2006, 09: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