Usings LEDs as input sensors, any tips?

OLDmarty

Senior Member
Hi All,

I've considered using LEDs as buttons, since reading how they can be used as photodetectors.

I'd like to have a LED illuminate once i touch it, basically a toggle on/off scenario.

I imagine the led will need to be driven with a chain of pulses to 'look' like it's always on (static), but when the LED is off (in between all the pulsing) would be when it's detecting a change in ambient light or a finger shadowing the LED.

Are there problems doing this? i imagine the light from the LED alters the ability to detect light in the off time between pulses, or are the leds so quick turning off that it won't effect the sensing operation???

Thanx in advance.
 

Goeytex

Senior Member
Might be doable.

LEDs turn off pretty fast but I cannot give you a specific number. The "persistence" we see is in the human eye so that anything faster than about 60 Hz appears to be constantly on.

If you PWM the LED at 100hz/ 50% duty. There will be a max of 5ms of off time to detect ambient light level. I would think that 1 ms would be more than enough. You will need a good OPAMP to amplify the voltage produced by the LED to a usable level.

See the link HERE for a simple circuit and more information.

The hard part will be isolating driver circuit from the measurement circuit at measurement time.
 

premelec

Senior Member
@ OLDmarty I tried something like this with an 08 long time ago - problem likely will be knowing when finger occlusion is 'real' compared to people passing by, clouds etc... you would have to define how fast and how much change registers for 'real' press... let us know if you are successful! - BTW at one time I use same pin for detect and then turn on LED - I guess that could be used for feedback that your input has been accepted...
 
Last edited:

OLDmarty

Senior Member
Thanx guys for all your input, well noted....

I guess the big question is how stable or reliable would a led "button" be?

If my equipment was in a dark control-room environment then maybe the ambient darkness in the room would prevent the LED from detecting if a finger is present, and obviously in a well lit room would be a different scenario.

Maybe the LED could reflect light off the finger to be detected? in either case, the led would maybe always be on, even if flickering at 100hz or more, so does that raise the issue of having a dull-lit led which then illuminates to full brightness when touched?
The dull-illumination would be ideal in a dark control room environment so you could still see 'where' the LED-buttons are located to aid touching them in the dark.

It's bit of a hairy project, but i like the idea of removing mechanical buttons & switches on a control panel to simply become LEDs that your touch and the LED will light to indicate the function required is now operating.

something to keep pondering...
 

techElder

Well-known member
Interesting ... yes, but it seems that there isn't much of a technical advantage over other ways to do this to meet those same goals. You still have to have mechanics of some sort to hold the LEDs in place.

A challenge ... yes.
 

OLDmarty

Senior Member
Interesting ... yes, but it seems that there isn't much of a technical advantage over other ways to do this to meet those same goals. You still have to have mechanics of some sort to hold the LEDs in place.

A challenge ... yes.
Yes, but 'no moving parts' would certainly be an advantage ;-)
 

hippy

Technical Support
Staff member
I guess the big question is how stable or reliable would a led "button" be?
The only way to find out may be to try it, experimenting with various set-ups and circumstances, particularly ambient light levels, to see how well it works.

The idea is plausible. I used LED's to monitor the presence of light and that proved it could work as other posters had suggested, but never went further than that.

PICAXE devices have on-chip comparators which may be useful for monitoring lower voltages or boosting those up to digital signals. The X2's have support for comparators built-in and it may also be achievable on some M2 devices by poking SFR's.

Another option may be to measure direct or reflected light when a finger is present or absent with a separate sensor. Using an acrylic light-pipe it may be possible to have separate illuminating LED and sensor in one unit, even a combination of visible LED, IR LED and IR sensor. If you can use something other than a LED as a sensor you will probably have an easier time detecting light directly or reflectively.
 

grim_reaper

Senior Member
It's bit of a hairy project, but i like the idea of removing mechanical buttons & switches on a control panel to simply become LEDs that your touch and the LED will light to indicate the function required is now operating.
In my experience, any customer that want to update a control room in that fashion ends up going down the route of replacing the panel with a touch screen HMI, or similar.
Is this your control panel or someone else's?! :D
 

hippy

Technical Support
Staff member
It's bit of a hairy project, but i like the idea of removing mechanical buttons & switches on a control panel to simply become LEDs that your touch and the LED will light to indicate the function required is now operating.
I had skipped over that part. One option is to use buttons which have LED's built into them. There are some with a mechanical disc or 'eye' which changes colour when pushed so there may be no need for an actual LED.

Unless you can get a LED detector to work reliably it may be a lot of effort for what turns out to be a frustrating and disliked experience for the user.
 

OLDmarty

Senior Member
I had skipped over that part. One option is to use buttons which have LED's built into them. There are some with a mechanical disc or 'eye' which changes colour when pushed so there may be no need for an actual LED.
Unless you can get a LED detector to work reliably it may be a lot of effort for what turns out to be a frustrating and disliked experience for the user.
Yes, i'm feeling this concept might head downhill, FAST! ;-)

Someone needs to start making LEDs with a sensor in the middle of them. lol ;-)

I just thought the led "button" would be a robust alternative to mechanical switches and fragile touch-displays.
 

AllyCat

Senior Member
Hi,

Have you considered using the "touch" inputs / circuitry available on some/most PICaxe pins? You should be able to use the same pin as is driving the LED, but may need to surround the LED with a small conducting ring (insulated from your finger), and very probably need "adaptive" software (not just a simple activation threshold value).

Cheers, Alan.
 

rq3

Senior Member
Hi All,

I've considered using LEDs as buttons, since reading how they can be used as photodetectors.

I'd like to have a LED illuminate once i touch it, basically a toggle on/off scenario.

I imagine the led will need to be driven with a chain of pulses to 'look' like it's always on (static), but when the LED is off (in between all the pulsing) would be when it's detecting a change in ambient light or a finger shadowing the LED.

Are there problems doing this? i imagine the light from the LED alters the ability to detect light in the off time between pulses, or are the leds so quick turning off that it won't effect the sensing operation???

Thanx in advance.
Marty, this is very do-able. A couple of thoughts for you. An LED can be used as a light detector in two ways. As a photoelectric generator, or as a photodiode.

As a photoelectric generator, the LED is basically a really small solar cell, and outputs a small voltage (and current) based upon the amount of light available to illuminate the LED. The maximum VOLTAGE you will get from the LED as a detector varies with the COLOR that the LED is supposed to emit when used as an LED, while the maximum CURRENT varies with the INTENSITY AND COLOR of the illuminating light. This method is useable, but very sensitive to the particular LED, it's color, and its environment. Without amplification, the LED response is difficult to use as the input to a Picaxe.

As a photodiode, the LED is reverse biased. In this condition, the current leaking through the LED is very small, but is directly related to the amount of light available to illuminate the LED (and its color). Because the LED has some internal capacitance, it is possible to quickly toggle the LED, connected between two Picaxe pins, from forward biased (to act as an light source), to reverse biased (to act as a photodiode). The trick is to quickly switch between reverse bias and then making the bias pin an ADC input to measure the residual voltage on the LED due to its internal capacitance. For a given sample rate, the brighter the light shining on the LED, the lower the residual voltage during the ADC measurement.

You can do this with a Picaxe at a rate that appears that the LED is constantly illuminated, but still sensitive to ambient light, or being covered by a finger. Do a bit of web searching, and you'll find that Forrest Mims covered a lot of this back in the late 1960's and early 70's. There was even a patent battle over it.
 

techElder

Well-known member
OLDmarty, the question is (while everyone is intent on telling what they have learned), do you want to create a new project or a new science?

I remember playing with this phenomenon 'back in the day', but there are so many ways to do this project without getting into 'basic research' that you should decide now and get it over with. :D
 

Flenser

Senior Member
The evilmadscientist have an example of this type of thing that they sell as their "Digitial Interactive LED" in both a ready-to-use and kit form:
http://shop.evilmadscientist.com/productsmenu/tinykitlist/556
http://shop.evilmadscientist.com/productsmenu/tinykitlist/411-octo

They solve the problem of how to work with, and without, ambient light by using an IR LED and phototransistor for sensing and turn on a seperate LED for the visible light output.

Their design is open source and at the bottom of the product page is a link to the documentation wiki that includes the schematic.
http://wiki.evilmadscientist.com/Octolively
 
Top