![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Just started experimenting with the bi-directional properties of LEDs hoping to figure out a way to use an LED as both a push button switch and as an indicator. Also wanted to see if I could use an inexpensive LED as a replacement for an LDR in a clock project to detect ambient light level. My first experiment accidentally produced a simple and fascinating Ambient Light Sensor and Display. I'm using a 16F690 with serial port module and a single red LED with anode connected to RA0 and cathode connected to RA1. Basically I light the LED for 50 usecs then I reverse bias the LED to place a capacitive charge on the LED junction. Then I set RA1 (cathode) to input while leaving RA0 (anode) at ground and I increment a counter at 1 msec intervals while testing for a change of state from '1' to '0' as the capacitive LED junction discharges. I run the discharge time value through a 16 step FIR filter to smooth the results and then I print the discharge time of 000 to 255 msecs to Hyperterminal. The results are stunning. The LED starts to flicker at around 40 msecs discharge rate (a moderately lit room) and slows all the way down to about 3 Hz in a dark room (discharge time >200 msecs). Well lighted rooms or sunlit rooms yield discharge times of anywhere from 10 to 30 msecs so the LED appears to be solidly lit. Shining a flashlight into the LED lens at very close range can get the discharge time down to 0-1 msecs. Putting your finger on the LED or casting a shadow on the LED will make the discharge time rise dramatically. Anyone should be able to duplicate this experiment. Please let me know if anyone wants to see my code and/or schematic and I'll post it after cleaning it up. Mike | |
| |
| | (permalink) |
| | |
| |
| | (permalink) |
| Filter is pretty much directly from PICLIST sourcecode library. Suggest you research FIR filters on your own. Here's a program excerpt showing how I'm using it; Mike Code: ;
; capture junction discharge time
;
discharge
incf binl,F ; bump counter |B0
skpnz ; |B0
incf binh,F ; |B0
DelayCy(1*msecs-6) ; 1 msec -6 cycle loop time |B0
btfsc PORTA,1 ; discharged? yes, skip, else |B0
goto discharge ; loop again |B0
movlw 255 ; |B0
btfsc binh,0 ; 256..511? no, skip, else |B0
movwf binl ; limit value to 255 msecs |B0
;
; Avg' += ( New - Avg )/16
;
filter16
movf avg,W ; |B0
subwf binl,F ; NEW = NEW - AVE |B0
swapf binl,W ; |B0
andlw 0x0F ; get /16 int part |B0
skpc ; result is neg? |B0
iorlw 0xF0 ; yes |B0
addwf avg,F ; |B0
swapf binl,W ; |B0
andlw 0xF0 ; get /16 frac part |B0
addwf avgfrac,F ; |B0
skpnc ; |B0
incf avg,F ; |B0 Last edited by Mike, K8LH; 17th August 2008 at 12:39 PM. | |
| |
| | (permalink) | |
| Quote:
Very interesting. I'll definitely have a play with that later.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| I posted something about this a while ago, using a op amp and a standard red LED to detect colors. | |
| |
| | (permalink) |
| | |
| |
| | (permalink) | |
| Quote:
Mike Code: while(1)
{
trisa = 0; // porta all outputs
porta = 0b00000001; // light the LED
delay_us(50); // for 50 usecs
porta = 0b00000010; // charge led junction
trisa.1 = 1; // RA1 (cathode) input
new = 0; // clear counter
while(porta.1) // while cathode 'hi'
{ //
new++; // bump msec counter
delay_ms(1); // delay 1 msec
}
if(new > 255) new = 255; // limit result to 8 bits (255)
avg += (new - avg) / 16; //
PutResult(avg); // send 000..255 'avg' via RS232
} Last edited by Mike, K8LH; 17th August 2008 at 01:21 PM. | ||
| |
| | (permalink) |
| This guy has made some experiments with LEDs as inputs. http://www.ivica-novakovic.from.hr/LedSensor-eng.htm Last edited by Gayan Soyza; 18th August 2008 at 06:49 AM. | |
| |
| | (permalink) |
| Hi Gayan, It looks like I'm doing exactly the same thing as the Gentleman in that link. --------------- I'm trying to reduce the junction discharge time. I placed a 100k resistor in parallel with the LED and the discharge time went down to zero so I wonder what value resistor might work? Mike Last edited by Mike, K8LH; 18th August 2008 at 02:04 PM. | |
| |
| | (permalink) | |
| Quote:
I ran some tests a few days ago using a MCP3302 on the PC's parallel port. Repeated for this post. Used a standard RED LED, the voltage scaling is a true representation of the LED Vout, no opa. Light source small hand torch [lamp] It shows on both traces on my analog logger. Thought you may be interested. Regard Eric.
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | (permalink) |
| This LED sensor stuff is interesting, going to give it a go on a Junebug. | |
| |
| | (permalink) | |
| Quote:
This plot is with 3 RED leds in series.
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | (permalink) |
| Hi Eric, Thanks for info'. Looks very nice on your analog logger. Mike | |
| |
| | (permalink) | |
| Quote:
I would imagine 5 Leds in series would be enough to be recognised as a logic '1' on a PIC pin, the '0' maybe a problem.???? You may have heard of the guy trying to get a quart into a pint pot, you are the only guy I know who can get a quart out of a pint pot. REF: Uncle Charlie...
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ Last edited by ericgibbs; 18th August 2008 at 02:49 PM. | ||
| |
| | (permalink) |
| Yes Eric, you've caught me trying to squeeze capability out of a PIC again (grin). I'm trying to avoid using the LED in photovoltaic mode. The reverse biased junction seems to have more than enough capacitance to hold a high charge for a while and it would allow me to matrix several LEDs using very few pins. I won't be able to reduce the number of pins to N(N-1) using a Charlieplexed matrix because a normal Charlieplexed matrix without driver transistors has pairs of LEDs back-to-back which drain the reverse charge but I suspect I can 'borrow' signals from a multiplexed display like that on my Charlie' Clock or perhaps use a Charlieplexed display with driver transistors in a non-traditional fashion. Wouldn't it be kind of cool using the six LEDs on one of those Blueroom boards as both input switches and as LED status indicators? Or instead of using the arrow keypad on my Charlie' Clock to switch between local time or utc time or to turn the appliance timer on or off, just press those indicator LEDs on the right side of the Clock? Fun stuff. Mike Last edited by Mike, K8LH; 18th August 2008 at 03:52 PM. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Ambient light proof distance sensor | samarsingla | General Electronics Chat | 15 | 5th February 2007 12:35 PM |
| Ambient vs Junction Temperature For ICs? | dknguyen | General Electronics Chat | 9 | 6th June 2006 10:43 AM |
| Mains light-on indicator | M.Joshi | Electronic Projects Design/Ideas/Reviews | 3 | 17th December 2003 09:52 PM |
| Help with circuit to light "sport mode" indicator | rlcanon | Electronic Projects Design/Ideas/Reviews | 6 | 2nd June 2003 03:09 AM |
| neon indicator light in a series circuit | whiterabbit | General Electronics Chat | 9 | 31st October 2002 10:14 AM |