An LED as a light Sensor


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    That is a really neat idea with some really good potential.
    I would be interested in your code and I think GCollier might be too
    bbarney

  2. #2
    Funky Gibbon's Avatar
    Funky Gibbon Guest


    Did you find this post helpful? Yes | No

    Default

    Hi BBarney

    This is my basic get you going proton code, there are alot of improvements that can be made, the procedure is:

    LED + connected to portb.1
    LED - connected to portb.0 through 330ohm resistor

    You will find that the led will flas fast in normal light, and slow in dark, my codes have some timing issues and are by no means perfect but they should give you the bulding blocks

    <code>
    device = 18f452
    xtal = 20
    dim timer as word

    start:
    output portb.0 'make pin output
    output portb.1 'make pin output
    high portb.1 'make led + high
    low portb.0 'make led - low led lights up
    delayms 20 ' small delay
    low portb.1 'make led + low
    high portb.0 'make led - low reverse bias led
    timer = 0 'clear timer
    input portb.0 make led - an input

    loop:
    if portb.0 <> 0 then timer = timer + 1 : goto loop 'if led - is not at logic low then increment timer and loop until it is logic low

    serout porte.1 , 84, [dec timer,13,10,0] ' sent the result to serial lcd

    goto start

    stop
    end
    </code>

    This is the same in ASM except im using porta.7 & 6 for led

    <code>
    LIST p=16f628a
    #include <p16f628a.inc>

    ORG 0000h

    START
    MOVLW 7
    MOVWF CMCON
    BSF STATUS, RP0
    CLRF TRISB
    BCF STATUS, RP0

    MAIN
    BSF STATUS, RP0
    MOVLW b'00000000'
    MOVWF TRISA
    BCF STATUS, RP0

    BSF PORTA, 7
    BCF PORTA, 6
    CALL DELAY
    BCF PORTA, 7
    BSF PORTA, 6

    MOVLW 0
    MOVWF TMR0

    BSF STATUS, RP0
    MOVLW b'01000000'
    MOVWF TRISA
    BCF STATUS, RP0

    LOOP
    INCF TMR0, 1
    BTFSC PORTA, 6
    GOTO LOOP
    MOVF TMR0, 0
    MOVWF PORTB
    GOTO MAIN

    DELAY
    MOVLW 0FFh
    MOVWF TMR1L
    MOVLW 0Ah
    MOVWF TMR1H

    DELAY_INNER
    DECFSZ TMR1L, 1
    GOTO DELAY_INNER
    MOVLW 0FFh
    MOVWF TMR1L
    DECFSZ TMR1H, 1
    GOTO DELAY_INNER
    RETURN

    END
    </code>

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thank's for the code Funky
    I'am working on something at the moment but I'll be playing around with this idea just as soon as i can get my other project done.I'll keep in touch
    bbarney

  4. #4
    Funky Gibbon's Avatar
    Funky Gibbon Guest


    Did you find this post helpful? Yes | No

    Default

    OK BBarney

    I should point out that the code is mine but the original concept is'nt so i can't take any credit for the idea, also it is a new concept to me also so im at the learning stage.
    i'll post updates on progress, there is some potential here for applications, not everyone has got photodiodes in their bit boxes but just about everyone has an led kicking around somewhere, besides i like the idea of using a device as emiter and sensor in one package

  5. #5


    Did you find this post helpful? Yes | No

    Default

    OK Funky
    that about sum's it up for me too you can pm anytime.talk too you later

  6. #6
    Join Date
    Mar 2006
    Location
    Garden Grove, Ca
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Led as light sensor

    Hi,
    I used leds years ago as light sensors for a solar tracker. I also remember taking the cap off of a ck722 transistor (Some of the first commercial transistors) and using it like a phototransistor.
    How's that for dating myself!!!!!

    Joe

  7. #7
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Joval
    How's that for dating myself!!!!!
    Doesn't "dating oneself" lead to hairy palms?

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. Led as a sensor ?
    By Kman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th May 2007, 07:57
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

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