An LED as a light Sensor


Closed Thread
Results 1 to 13 of 13

Hybrid View

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

    Default An LED as a light Sensor

    Hello,
    Im new to this forum and i dont know if this subject has been covered before but i just had to share it as i think it's coolest thing i've ever seen

    We all know LED's emit light, did you know they can be used as a photodiode too?

    I've read the theory, tryed it and yes it works, the theory is simple to understand if you are familiar with rc time

    Take a look at the video here
    http://mrl.nyu.edu/%7Ejhan/ledtouch/index.html

    then read the theory here
    http://www.merl.com/reports/docs/TR2003-35.pdf

    im sure you'll be amazed too, or mabey im just easily pleased, if anyone has difficulties in coding the theory im quite willing to share my own code written in ASM & Proton

  2. #2


    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

  3. #3
    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>

  4. #4


    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

  5. #5
    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

  6. #6


    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

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