Shop OBEX P1 Docs P2 Docs Learn Events
BS1 driving an led as a sensor — Parallax Forums

BS1 driving an led as a sensor

SesrunSesrun Posts: 2
edited 2006-04-17 17:13 in BASIC Stamp
I read over forums.linear1.org/index.php?PHPSESSID=66595e369ddf5934339180c4605c62f6&topic=445.15 about using an led as a light sensor...I then tryed to illustrate this principle using a bs1 by hooking up a single red led to pin0(long end) and pin1(short end), I also hooked up a serial LCD to pin 7, I then wrote this program which just contently displays 0 no matter if I was shinning a red led at the led on the stamp or not. Here is what I tried:

' {$STAMP BS1}

PAUSE 1000
SEROUT 7,N2400,("    TEST")

SYMBOL result = W1
SYMBOL half = B4
half = 1/2
loop:
     'turn on led
       HIGH 0
       LOW 1
     'invert poleraty for 10ms and measure time of discarge of led
       POT 0,255,result
     'invert result
       result = result*half
     'Output value of result
       SEROUT 7,N2400,(254,1,#result)
     'Repeat
       GOTO loop




Any suggestions would be appreciated, thanks in advance.

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-16 23:59
    There was a considerable thread on this very subject a few months ago.· I must not be using the right Search combination (because I can't find it, yet.)
  • FlyingFishFingerFlyingFishFinger Posts: 461
    edited 2006-04-17 00:01
    I did a quick search (Google)...interesting property I've never heard of. Here's one of the things I found:

    "Here's a circuit that takes advantage of the photo-voltaic voltage of an ordinary LED. The LED voltage is buffered by a junction FET transistor and then applied to the inverting input of an op-amp with a gain of about 20. This produces a change of about 5 volts at the output from darkness to bright light. The 100K potentiometer can be set so that the output is around 7 volts in darkness and falls to about 2 volts in bright light."

    Cheers

    Rafael
    549 x 164 - 2K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-17 02:25
    PJ,

    ·· I believe this is the thread you refer to:

    http://forums.parallax.com/showthread.php?p=570497

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-17 03:22
    Sesrun -

    Since the PBASIC Stamp can only do integer math, the follwing expression will not give you what you expect it will:

    half = 1/2

    The variable "half" wll NOT = .5 after that line is executed, as rounding will occur. Check your PBASIC Stamp Manual for details.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • SesrunSesrun Posts: 2
    edited 2006-04-17 17:13
    Here's some code I found will work...thanks for the help

    SYMBOL pulse = W1
    
    Main:
      HIGH 0 'blink LED
      LOW 1
      HIGH 1 'sense light
      LOW 0
      PULSIN 1, 1, pulse 'measure discarge time
      IF PULSE>0 THEN l6
      IF PULSE<1 THEN h6
      GOTO Main
    
    h6:
      HIGH 6
      SEROUT 7,N2400,(254,1,"pulse = ", pulse,254,192,"Backlight is On!")
      GOTO Main
    
    l6:
      LOW 6
      SEROUT 7,N2400,(254,1,"pulse = ", pulse,254,192,"Backlight is OFF!!!")
      GOTO Main
    
    



    This code works with the pos end of a led on pin0 and neg on pin1, a serial lcd on pin 7, and the lcd backlight hooked up to pin6 and ground. Thanks for all the help and suggestions...

    -Ryan
Sign In or Register to comment.