Shop OBEX P1 Docs P2 Docs Learn Events
LED Touch Sensor — Parallax Forums

LED Touch Sensor

Steve JoblinSteve Joblin Posts: 784
edited 2011-08-22 08:54 in General Discussion
Just saw this via Make.com... looks pretty cool!

LED Touch Sensor

The Physics

Light Emitting Diodes (LEDs) have a natural capacitance, and that capacitance and/or impedance is dependent on the light incident on the diode. (Clearly I need to read up on my device physics).· By reverse biasing the diode, we charge the capacitor. By turning the high leg when charging to an input, and holding the other leg at ground, we source current from the device. Since the RC time changes as a function of ambient light, by choosing a time to poll after the previous hi to input transition, we check to see if the state of the input is high or low. This high/low is our LED switch.

What you need

A micro-controller with ms resolution and at least 2 I/Os, and an LED.

Steps
  1. Turn the LED On for 1 ms
  2. Reverse Bias the LED for 1 MS
  3. Turn the Hi in the last step to an input, and wait for 1 - 20 ms.
  4. Repeat steps 1 - 3

·attachment.php?attachmentid=47636

You’ll need to play with that number based on ambient light and LED properties, so it’s handy to make that adjustable during run time. If you find that the LED discharges too quickly, you can either increase the charge time in step 2 OR add a small resistor (100 to 470 ohms) in series on either side of the LED (remember t is proportial to R*C). The resistor in series will also limit the current (which is good for the LED) but it will also limit the intensity when the light is on.

Basic Stamp Code


Here’s a quick demo to get you going with a basic stamp, using pins 1 and 2

‘ {$STAMP BS2}
‘ {$PBASIC 2.5}

pausetime VAR WORD
trigger VAR WORD
polltime VAR WORD

pausetime = 1 ‘Set time between steps
polltime = 10 ‘Set time to poll after swtiching to input

Main:

‘Light ON
HIGH 1
LOW 2
PAUSE pausetime

‘Charge
LOW 1
HIGH 2
PAUSE 1

‘Input
LOW 1
INPUT 2
PAUSE polltime

IF IN1 = 0 THEN
trigger = 1
DEBUG “On”
ELSE
DEBUG “Off”
ENDIF

GOTO Main

Post Edited (Steve Joblin) : 6/9/2007 1:01:47 PM GMT
«1

Comments

  • NewzedNewzed Posts: 2,503
    edited 2006-06-02 17:28
    In the input routine, shouldn't that be:

    pause polltime

    Thanks

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-02 18:03
    Yes, Forrest Mimms was always touting using LEDs as sensors.

    And there have been guys putting patents in to use the display (LEDs) of a device as a means of communication, such as data sending, flashing, etc...

    Look here:
    http://mrl.nyu.edu/~jhan/ledtouch/index.html

    I have set up reading a line of LEDs as a sensor (and output at the same time!)

    I plan to write an app note about it in the near future.

    With the stamp I used RCTime to read levels...

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-06-05 08:13
    Take a look at http://www.sensorsynergy.com/helpfulhints.htm for Helpful Hint #1: Using Inexpensive LEDs as Optical Detectors.

    Apparently color choice can make a difference in response to ambient light conditions.· And there is more...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-05 16:22
    Yes Kramer, I found that green LEDs seemed to work the best (of the LEDs I have here at my desk)- I'm sure that different brands will provide different results as well.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • DgswanerDgswaner Posts: 795
    edited 2007-04-23 17:06
    I'd love implement this into my current/future projects. Can someone provide a schematic, it looks like the one posted in gone. I'm guessing that multiple LEDs could be used as one input, I would just need to tweek the numbers to account for more LEDs. I want to use this as a button and just read on/off rather than a touch sensor like in the video link. I searched the web and can only find the one video. and no schematic. from what I gather I connect it like the RCtime example in the BS2 book. any help would be appreciated.

    thanks
  • mattgilbertmattgilbert Posts: 1
    edited 2007-06-07 18:49
    i would also love to get a hold of that schematic, or a similar one.

    also, ryan, any news on the app note? that would be really helfpul.
  • D FaustD Faust Posts: 608
    edited 2007-06-07 19:43
    Steve Joblin·said...
    IF IN14 = 0 THEN
    Did you mean IN1 because nowhere do you mention pin 14?··Also,this senses how much light it recieves (if it is covered or not) rather than physically touching it, right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-06-09 13:01
    It looks like my post was sabotaged... I found the original "schematic" and made the corrections to the program. How was someone able to get in and change my post anyway!?
  • D FaustD Faust Posts: 608
    edited 2007-06-09 15:56
    That looks better. I know the forums moderators can access posts, but as far as I know other members can't.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • D FaustD Faust Posts: 608
    edited 2007-06-09 18:46
    Does anybody know if using an IR led would only sense ir light?· Thanks in advance.· Instead of setting pin 2 as an input and waiting polltime could you use RCTIME to see how long it takes the led to discharge.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust

    Post Edited (D Faust) : 6/9/2007 7:21:58 PM GMT
  • ghost13ghost13 Posts: 133
    edited 2007-06-09 18:49
    Could you please repost the schematics? Thanks
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-06-09 21:24
    Interesting idea D Faust!· I was thinking the same thing about IR... I have a few extra laying around, so I will experiment and let you know... Don't know about RCTime... I'll try that as well...

    I noticed that none other than Parallax's own Chris Savage had edited my post... don't know why he did, but his name was showing on the bottom of my posting!
  • MikeKMikeK Posts: 118
    edited 2007-06-10 01:37
    IR: Why would you want to? The point is to make a lit "button" isn't it?

    From the link above:

    "Rule of thumb #2: LEDs will only detect light of wavelength shorter than the wavelength of light that the LED would emit if it was put in a circuit that forward biased the LED.

    For example, a red LED will detect light emitted by a yellow LED and a yellow LED will detect light emitted by a green LED but a green LED will not detect light emitted by a red or yellow LED. All three LEDs will detect "white" light or light from a blue LED. White light contains a blue light component which can be detected by the green LED. Recall that visible light wavelengths can be listed from longest wavelength to shortest wavelength as Red, Orange, Yellow, Green, Blue, Indigo, Violet (remember the mnemonic "Roy G. Biv"). Violet is the shortest wavelength light with the most energetic photons and red has the longest wavelength light with the least energetic photons of all of the visible colors of light."

    Mike
  • D FaustD Faust Posts: 608
    edited 2007-06-10 11:21
    What I was getting at was using one as an IR photoresistor rather than a button.· Does the fact stated above mean that sensing IR with leds is impossible?· They don't make radio frequency leds, right?· See picture:· EHF through LF is radio.

    radio-spectrum.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • ForrestForrest Posts: 1,341
    edited 2007-06-10 11:42
    For sensing IR, you would use an IR detector (which just happens to look a lot like a black LED)
  • D FaustD Faust Posts: 608
    edited 2007-06-10 19:52
    Okay.cry.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2007-06-16 12:24
    I read this post and thought the idea of an LED light sensor was a great idea.· So I set out to test the idea, so far I have not been successful.· I read this post as well as a document I found on-line:·http://www.merl.com/papers/docs/TR2003-35.pdf·and completely understand how to go about programming this.· I have attached my Spin code for the Propeller.
    ·
    The attached jpg is a screenshot from my BitScope showing the voltage after the resistor just before it goes into P7 on the Propeller.· The slope downwards is the capacitance of the LED discharging when I turn the output of the cathode to an input.· The problem is that I don't see the slope change at all when I am covering the LED versus being in full bright light.· Also I have changed LEDs and only see a very very slight change in capacitance, but again no change if I am covering it or it is out in the open.
    ·
    Any suggestions?· Maybe I need a different type of LED.· I am using·the diffused lens variety; perhaps water clear lense is better?· The circuit has the Anode of the LED attached to P6 and the cathode of the LED is attached to a resistor and then the resistor is attached to P7.· Can't be any easier, right?
    ·
    Wait a minute - it appears the slope downwards is not due to the LED capacitance.· I just pulled my green LED out to verify one more time that a yellow and·a red LED give the same results and I see the waveform does not change.· The waveform bare·adjust without a completed circuit.· Hmm....does that mean the internal capacitance of the pin is causing the slope?
    ·
    OK - so my problem is that I don't see a slope from the capacitance of an LED.· Any suggestions?·

    ·--edit: uploaded correct code

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter
    tdswieter.com
    One little spark is all it takes for an idea to explode

    Post Edited (Timothy D. Swieter) : 6/16/2007 12:39:27 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-06-16 12:41
    Y'know...· where this whole trip began... was, leastways round these parts,·in a research article... the goal was to minimize I/O in/for a two-way (half-duplex) data link.·

    It's interesting, in a cutey-pie way I suppose,·the little projects and all, but the rubber on this jalopy simply doesn't meet the road -- the demonstrations are always (surprised?) in a dark room.· As you're discovering, using an LED as a substitute for a switch just isn't living in the real world.
  • NewzedNewzed Posts: 2,503
    edited 2007-06-16 12:47
    I built up a board with six LED sensors that worked fine.· The trick is - you have to put a piece of black heatshrink around the LED so only the very tip is exposed.· Otherwisethe LED absorbs too much light from the side.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2007-06-16 12:53
    Thank you Newzed. I dug out my parts from the Toddler and added one of those black tubes around my single LED but I still do not see any change in capacitance. Does there need to be more than one LED present for the concept to work? One LED emitting while another one is discharging?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter
    tdswieter.com
    One little spark is all it takes for an idea to explode
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2007-06-16 12:59
    AH HA!!!! My probe was messing it up and loading the line down. I detached my probe and voila! This is pretty neat stuff!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter
    tdswieter.com
    One little spark is all it takes for an idea to explode
  • NewzedNewzed Posts: 2,503
    edited 2007-06-16 13:15
    Timothy, I have attached my BS2 program for controlling six LED switches.· Maybe it will be of some help.· You can just delete or disable the LEDs you don't use.· My LEDs were a bit close together so I used a piece of balsa wood painted black to cover each LED.· If they are far enough apart you can just use your finger.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
  • NewzedNewzed Posts: 2,503
    edited 2007-06-16 20:25
    Timothy, is your LED sensor working OK now?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2007-06-16 23:38
    I got it working just before you posted the code.· My oscilloscope probe was loading the line down and as soon as I removed it I started seeing the varied capacitance.· I think this is pretty neat.· What LED color were you using?· I have tried red, yellow, and green and so far the green works the best like the post earlier said.

    Later I will dig out some blue LEDs and try them.

    Also it appears to work best in a room with light.· The light in the room versus a close finger provides a greater difference in the capacitance than a dark room.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter
    tdswieter.com
    One little spark is all it takes for an idea to explode
  • NewzedNewzed Posts: 2,503
    edited 2007-06-16 23:41
    Timothy, the brighter the light the better it works.· I also found that green works the best of all colors, including blue and white.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • HughHugh Posts: 362
    edited 2010-07-28 19:54
    Timothy,

    I have [noparse][[/noparse]crudely] modified your code to:
    a) Drive four 3mm red LEDs, using one cog per LED (all the spare pins on the demo board)
    b) Use a 'SetPoint' threshold that is the average of the Calc_Values from all four LEDs (helping to deal with ambient lighting conditions)
    c) Create some 'bargraphs' (i.e., rows of '#' characters) on a VGA screen
    d) Reduce the 'ms' delay

    From 25m I could detect the output of a 3mW laser driven by 4.2V - getting the beam to line up with one LED was the difficult part. At 25m I ran out of garden...

    Red laser + green LEDs were no good.

    Photodiodes + IR were no good.

    Photodiodes + red laser were no good.

    It does seem very sensitive, but not (yet) sensitive enough to send data, mainly because of the cycling of the LED. The great things is that I haven't used any resistors, capacitors or Op-amps - I have a digital brain and these fiddly things are too like 'shades of grey' for me!

    Cheers
    Hugh

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • Peter KG6LSEPeter KG6LSE Posts: 1,383
    edited 2010-07-29 14:22
    I Use 10 mm LEDs as receivers for stuff all the time . they work well for the price of "free" .
    I too found the green ones are the most sensitive to ambient light .

    when I was developing the PhotoPhone ,I got over 500 Feet with a green DPSS laser .

    From what I found its s LOS ( line of sight) issue .

    Peter KG6LSE

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Carpe Ducktum" "seize the tape!!"
    peterthethinker.com/tesla/Venom/Venom.html
    Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway. —Tanenbaum, Andrew S.
    LOL
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-07-31 15:04
    This is a really great project. I used LEDs as sensors some years ago, experimenting with robots and control panels. I remember filing the top LED surface until it was flat and testing the results. The color of the LED is very important. I experimented with IR, red, yellow, green, and blue. There's much documentation about this as some LEDs are more suited than others. I like the idea of making a "poor man's sensor" for about five cents. It's good on the budget.

    Humanoido
  • Peter KG6LSEPeter KG6LSE Posts: 1,383
    edited 2010-07-31 19:08
    It was SO funny that I discovered the same thing Forrest did 20+ years ago . I had no clue LEDs were light sensitive until i mixed up a bag of Water clear LEDs and a bag of photo diodes . I talked to Forrest about 5 years ago and we had a laugh about it . His little books is the shear reason iam in to electronics . i got my first iron at 7 and I have never bean normal since then Hehe.
    Peter KG6LSE

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Carpe Ducktum" "seize the tape!!"
    peterthethinker.com/tesla/Venom/Venom.html
    Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway. —Tanenbaum, Andrew S.
    LOL
  • ZootZoot Posts: 2,227
    edited 2010-08-01 03:22
    Here's one of the definitive docs on this technique. Besides general sensing, the authors discuss data rx/tx techniques with two identical LEDs (they get about 250 bits per second across a distance of several inches.

    The time cycle for each reading can be made consistent (and speedier) in two ways -- tuning the RC portion of the circuit for faster discharge times, and deciding on an upper threshold of the RC time measurement. In my own projects, I nearly always include an LED-as-light-sensor, as the same LED can be used for a hearbeat indicator, etc (presuming I have two free pins, that is).

    citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.69.1570&rep=rep1&type=pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
Sign In or Register to comment.