LED switch
Newzed
Posts: 2,503
Here is a neat little program, adapted from an earlier post about LED Touch Sensors.· It will work on any Stamp, using any two adjacent pin headers.
When the CHG pin goes high the program jumps to a little routine which toggles an LED on Pin 14, but it could jump to a GOTO, a GOSUB, or anything you like.· You don't really have to touch the LED - just momentarily block off the ambient light.· I had it working in several light levels.· The only thing is, if the ambient light level gets too low then CHG will stay high.· Different LEDs will probably work different - I'm using a resistorized diffused high efficiency red LED.· I've got a 31 cent pushbutton!!
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
When the CHG pin goes high the program jumps to a little routine which toggles an LED on Pin 14, but it could jump to a GOTO, a GOSUB, or anything you like.· You don't really have to touch the LED - just momentarily block off the ambient light.· I had it working in several light levels.· The only thing is, if the ambient light level gets too low then CHG will stay high.· Different LEDs will probably work different - I'm using a resistorized diffused high efficiency red LED.· I've got a 31 cent pushbutton!!
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
bse
943B
Comments
Thank you, Tom Perkins
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
PLEASE correct me if I'm wrong here, but if some poor rookie ran across your "LED Switch" posting and program, slapped any old LED across two Stamp pins and ran the program, he may stand a good chance of blowing a Stamp pin?
If I understand the program correctly, I'm not sure that "I'm using a resistorized diffused high efficiency red LED" is enough of a forewarning. Perhaps you might want to add to the original post: "A resistor is REQUIRED in series with the LED. Failure to do so ... etc".
My apologies if I'm mis-understanding what's happening here. I'm just a software guy
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
I guess there are really two anwers to your question:
1. The program provides for EASILY changing the delay parameters, so what are the chances that this proposed "rookie" ISN'T going to fool with them?
2. This "rookie" might be a student, as well as 6' 4" 325# pulling guard on the UCLA football team. Are you willing to take the chance that he won't find out where you LIVE?
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Thanks for posting your work on this. I have been watching the other topic on this subject and wanting to spend some time playing with it myself.
Have you tried using an LED display to do this? Maybe something like - touch the top of the display to toggle ON and the bottom to toggle OFF. Or maybe to move a servo arm one way by touching the top and then the other way when you touch the bottom.
Russ
I using just a single LED at the moment.· Since it toggles each time you block the ambient light, I didn't even consider another one so I would have an On-Off switch.
The present sequence takes 12ms plus overhead, which means in could be inserted in a servo pause or almost anywhere.· I playing around with the polltime to see how much I can shorten that.· What I have in·mind is setting up the switch routine as a GOSUB, then I can just call it from anywhere.· I'll post any results of the polltime duration here as soon as I finish.· I want to try a green and a yellow to see what difference they make.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
I have attached the program so you can see just what I did.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
this one really is excellent.
I have a 'bar' of 5 and a 'bar' of 12 leds which may act as a kind of pre-packaged slide switch.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
You have made it look pretty simple. I've have got to find some time to play with this myself!
It seems to me that this concept could be used to select a program to run on a BOE-BOT, or some thing like that. With two LEDs you could count to 4 menu options by having them on most of the time in a display mode. When they are in switch mode then then one led would be used to increment the menu item count and the other to select the item.
Need some time to play with this...
Russ
Thank you, Tom Perkins
i suppose i is even a 'simple' project, almost... connect a LED matrix, figure out the code to read the LEDs as a switch, scan the rows, have a PC application display the data... a VB to macromedia flash interface would be great for this...
so, get the position, send it to VB, have VB send a 'height' variable to a macromedia movie... this could become quite a dramatic interface system for art\interactive stuff..
if chg = 1.......
to
if chg = 0 ...............
Turned the Stamp on, all 16 LEDs were flashing.· Turned my desk lamp off, they all quite flashing.· Turned the desk lamp back on and they all started flashing again.· This would make a great little device to turn outside lights when it got dark.· By adjusting polltime you could even turn on lights when it got really cloudy.
I'm going to try to add another LED switch to my board and see if I can run them both at the same time, but have them do different things.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Its really exciting to see parts like that to do work other than they designed to do!!! Really cool!! I might intergrate it on my next project!
Regards Thanos
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greekbotics: Greek Robotics Forum
LED On/Charge/Input routine for each switch - I ran into a conflict when I tried to run them simultaneously.· The program for the two switches only takes 108 bytes.· I am using green LEDs for the switches.· I need to make a little board to hold the LED switches - I think it would be a mechanical improvement.· Then I'll try for four switches.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Finally got my quad LED switch going. A little aside - having my little SuperMill is just great - need a simple little board, I just lay it out, go out to the shop and in 30 to 45 minutes I’ve got my little board, all nicely etched and drilled.
To press on, I have 3 green LEDs that perform tasks when they are activated. The fourth LED is a red one, and it acts like a panic button. Activate it and the program goes into STOP mode. You have to reboot to continue.
I made a little cable for the green LEDs that plugs into the AppMod adapter – keeps the BOE clear. The red LED plugs into Pins 1 and 3 on the header alongside the BOE.
I connected my O’Scope to one of the switch LED pins to measure the cycle time. The elapsed time from when a switch starts its routine to the time it starts it again is about 86ms.
If you decide to build one of these switches, be sure you remove ALL traces of flux. Just a tiny bit of residue on the LED pins wreaks havoc with the timing and the CHG pin will never go high.
I have attached the program just in case.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
The Stamp drives a ULN2003 in response to a switch activation.· As Chris Savage pointed out, if Pin 9 of the 2003 is left unconnected, the 2003 functions like a normal 7-transistor array and can drive almost any non-inductive·device.
I had posted some questions·on the Basic Stamp forum about the possibility of serouting via the 2003 and the consensus was "Probably".
I didn't have another BOE immediately available, so I hooked my O'Scope to output Pin 16 of the 2003, which was also driving an LED, and modified my program so that when Switch·1 was activated in would serout
%10101010 to Pin 1 of the 2003.· The scope displayed what appeared to be the same thing except it was inverted, which I had expected.· It appears the 2003, with Pin 9 disconnected, will handle serouts which makes this a really flexible board.· I'll have to hook another BOE to prove this out, of course, and I think I'll change the baud rate to 2400 instead of the 9600 I used for the test.· I did not have a pullup resistor on Pin 16 - I think leaving the LED in place served as a pullup.· I'll have to look into that further.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
if chg1 = 1 then
serout 8, baud, [noparse][[/noparse]"A", "B", "C"]
toggle 8
pause dly3
endif
Pin 9 of the 2003 was floating.
I hooked up another BOE and connected a wire from Pin 8 of the Quad LED to Pin 0 of the BOE.· Baud for the Quad was set at 16780 and for the BOE at 396.
When both Stamps were programmed I connected my serial cable to the BOE.· When Switch 1 on the Quad was activated the BOE displayed:
Received A· B· C
I guess that proves that.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
···I did alittle experiment outside the stamp circuit to see what is happening.·· I reverse biased a LED and pointed light at it.· When I do this, my multimeter shows a current of less then 1uA. Am I doing something wrong?· Is a diffuse LED somehow important?
Cool project. Just curious, while using a green led found that if I reversed the connections the led would still react to light? If I use yellow or red then the anode must be connected to pin 1 to work. Also to be sure I have this right are the leds supposed to blink? Haven't made it to your quad program yet still running through all the options of what can be done with your program. Thanks.
Cheers, Michael
You can perform any task you like when the CHG pin goes HIGH.· I have been playing around with the Quad, and first of all, I found out that everything still works if Pin 9 of the 2003 is tied to 5VDC, and that the 2003 can perform any task.· For instance, here is the routine for Switch 1:
'if chg1 = 1 then toggle 8
'if chg1 = 1 then gosub blink1
'if chg1 = 1 then gosub talk1
blink1:
for x = 0 to 5
toggle 8
pause 500
toggle 8
next
return
talk1:
serout 8, baud, [noparse][[/noparse]"A", "B", "C"]
return
I just uncomment whichever of the three options I want to use.· In the first option, Pin 8 could turn and LED On or Off, or I could connect it to an external relay to to control a peripheral.· The first board I made only used 4 of the 2003's 7 outputs,· I am making another board what will use all seven 2003 outputs.· Then I will have a very flexible control panel that can perform any number of tasks.· The 4 LED switches and the 7 2003 outputs leave 1 I/O pin, plus Pin 16 for debugging, which is OK since this is just a control panel and does nothing else.
The serout option talks to a BOE, which could interpret the command received to perform any task I desire.
I have found that the LEDs for the switches can be standard LEDs without the normal limiting resistor since the duty cycle is quite low, and I will use these on the new board to see if they will hold up over a long period of time.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
1. Has anyone tried an Analog to Digital input?·
The 8x8 matrix in the video appears to be responding in that way and it would be nice to use the LED as more than a toggle.
2. Has anyone tried more exotic LEDs?·
Seems there are narrow band and broad band versions that provide faster responose times.
I acquired what I think are IR photo diodes [noparse][[/noparse]labled in cryptic Chinese] that I was considering using instead of CdS photoresistors on a robotics project·[noparse][[/noparse]they may be too narrow band for tracking daylight]. · I also have one other photo diode that senses in the daylight range and I wonder about trying it.· In doing some Googling, I come up with more options and more questions.· There are also P-I-N- diodes that seem very responsive as they work with microwaves, but I am not exactly sure what they might offer.
I suppose that it is easiest to 'keep it simple stupid' and use the generic colored·diodes as they work and come in a prefabricated matrix, but an ADC input still appeals to me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you want more fiber, eat the package.· Not enough?· Eat the manual."········
This is a very interesting and broad subject. Let me see if I can shed some more light on it......... (pun intended)
Regarding A/D input: As I normally use a "virtual" A/D in SX applications..... you know the two resistor and one capacitor plus a few lines of software trick, I have experimented with detecting light levels from photo transistors, and photo diodes, as well as regular diodes. While I really like the simplicity, flexibility and low cost (about 5 cents) of the virtual A/D, unfortunately its input impedance is not super high...... a few megohms at best. Hence one has to be very aware of that fact when working to use it to detect light levels using regular LEDs as sensors. To get a significant response, the LED's load impedance needs to be very high; 10 MegOhms or grater if possible. With some consideration the virtual A/D can probably made to work at 2 Megohm, or possibly 5 Megohm input impedance. At levels higher than that, the SX input leakage currents can get in the way and distort things.
Using regular photo diodes will give increased performance since they are optimized for sensing light, rather than an LED whose principal purpose it is to emit light. Essentially, they are a very small current source, providing electrons as a function of incident light level at some frequency(ies). These devices have good predictable response times, and work great with a virtual A/D, even with somewhat lower impedance levels. PIN diodes are extremely fast, typically responding in a mere 2 or 5 nano seconds; a "must" for high speed optical communications such as fiber.
And then of course there are the photo transistors which detect light similar to the photo diode, but include gain on top of that detection, and hence bring the sensitivity up another level. Typically they are slower than photo diodes due to capacitance in the base junction. Sometimes the base of the transistor is pinned out so you can mess with the detection parameters.
Darlington photo transistors are again more sensitive, but they suffer horrendously from slow speed due to the internal capacitances of the first trasistor's junctions being effectively "multiplied" by the gain of the second transistor. But great sensitivity at very slow speeds. Due to the unpredictability and temperature sensitivity of the gain of the cascaded transistors, it can be very difficult to use these devices in ambient light conditions. Reliably setting detection thresholds with these devices is a very frustrating exercise. Temperature excursions alone can vary the "idle" current over a range of 10,000 to 1; a very difficult issue to deal with for stable operation.
One way to improve rejection of ambient sources (visible or infra-red) is to use a light source that is pulsed at some frequency, and then look for that frequency in the signal detected by the receiver. This is sort of akin to "DSP", and I have done this with an SX operating a 20 foot open air optical link in sunlight at 115 Kbaud. So, lots can be done if you put some thought to it.
One significant variant in light detection with ordinary emtting LEDs is the "beam width" angle of the lens. Reciprocity tells us that the range of emission angle will be the same as the acceptance angle. So very conveniently one can light up the LED, determine its principal emission distribution, and the be confident that it's reception zone will be the same angle! Many of the modern bright LEDs have a very narrow emission angle.
I have not yet experimented with irradiating various clear lensed "coloured" LEDs with different colours; such as hitting a "yellow" LED with light from a "red" LED. Also I have found that diffuse or colored lensed LEDs are not very sensitive.
I plan to try the "LED switch matrix" concept with ambient rejection by pulsing the source LEDs at a particular frequency, and looking for that frequency in the detectors. Additionally, the concept of an analog equivalent of "how hard the virtual switch is being pushed" is intreaging. There could be many applications.
Thanks for your interest Kramer....... have fun experimenting!
Cheers,
Peter (pjv)
I'll stay away from the Darlington Photo transistors. They seem quite difficult. I was wondering if the PIN diodes were too esoteric, they seem to be the highest performance, extremely sensistive, and best saved for modulated light reception.
After posting the above, I came across some 8x and 16x ADCs from National Semicondutor. These would seem to be optimal for 8x8 and 16x16 LED grids at they would not tie up the microprocessor as much. I guess you could make an SX-28 handle 8ADCs and provide serial output. It appears that would also allow you to easily use the matrix format with a BasicStamp being supported by the SX-28.
Is it possible that the SXes virtual ADC approach can be very useful for creating taylored proximity detection in things like the SumoBot, line detections, and their industrial counterparts? I do want to get rid of my CdS photoresistors and use good photodiode on my BOEbot for light navigaton. I can put them in tubes, add lens, and even add some motion control! One SX-18 can do all that and send a 2bit code [noparse][[/noparse]left-right-both-off] to a BS24.
Right now I am trying to get a small CANbus transciever board adapted to Parallax products. I started this years ago, but I didn't have a clear vision of what I wanted. A few days ago, it became quite obvious.
After having this hardware ready for an optimal Home Automation network, the LED matrices look very appealing as an input device with an LCD menu. An expensive chassis and cutting holes anything is nearly eliminated.
Everything could be mounted on the underside of a clear acrylic plastic that can be printed with lables and masked.
In other words, the LED sensor seems to be an optimal DIY interface with any microprocessor. It is all quite exciting.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you want more fiber, eat the package.· Not enough?· Eat the manual."········
Post Edited (Kramer) : 6/19/2006 5:33:33 AM GMT
I did not mean to scare anyone away from Darlington photo transistors. Its just that they can be a bear when ambient light is uncontrolled and if temperature variations are prevelant. They are otherwise very sensitive and quite usable if those two issues are considered.
Again, regarding virtual A/D in an SX; I would bet that the virtual's software of 8 or so lines of assembler application code, will be much shorter than the code to interface serially to an external A/D. Why is the world having such a hard time grasping this ?????
For modest performance (4 to 10 bit resolution) and modest speed (100 to 1000 conversions per second) and trivial cost (5 or 10 cents) it's the only way to go; each A/D consumes only 2 port bits, and some of the code is common among multiple A/Ds.
If one's need for speed performance was indeed very modest (10 to 100 conversions per second), then the traditional circuit can be simplified even further utilizing only 1 port bit per A/D at a cost of another couple of lines of code. This means an SX could have as many as 20!
Anyhow, enough rambling...... I'll get off my soap box now.
Cheers,
Peter (pjv)
There is even an SXDemo already written code that moves the output to an RS-232 port and includes other feature that I can remove.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you want more fiber, eat the package.· Not enough?· Eat the manual."········