12F629 LDR - Light Dependant Resistor


Results 1 to 16 of 16

Threaded 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  

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