Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 17th August 2008, 02:10 AM   (permalink)
Default LED as Ambient Light Sensor & Indicator

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
Mike, K8LH is offline  
Old 17th August 2008, 03:39 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
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.
Could u explain a bit on FIR filters and how u implemented it?
asp1987 is offline  
Old 17th August 2008, 03:47 AM   (permalink)
Default

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.
Mike, K8LH is offline  
Old 17th August 2008, 03:50 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
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.
Stop it! This shiny thing could distract me from my SD card project. Must resist! Shutting off browser and back to coding.

Very interesting. I'll definitely have a play with that later.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 17th August 2008, 04:05 AM   (permalink)
Default

I posted something about this a while ago, using a op amp and a standard red LED to detect colors.
Krumlink is offline  
Old 17th August 2008, 04:22 AM   (permalink)
Default

http://www.robotroom.com/ReversedLED.html

found the link.
Krumlink is offline  
Old 17th August 2008, 01:08 PM   (permalink)
Default

Quote:
Originally Posted by futz View Post
Stop it! This shiny thing could distract me from my SD card project. Must resist! Shutting off browser and back to coding.

Very interesting. I'll definitely have a play with that later.
Sorry (grin). If you do get back to it, it's pretty simple. Perhaps it might look something like this in BoostC??? It should even work fine on a 12F683 with that bit-banged BoostC serial I/O demo' code. Or driving an LCD, etc...

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.
Mike, K8LH is offline  
Old 18th August 2008, 06:49 AM   (permalink)
Default

This guy has made some experiments with LEDs as inputs.

http://www.ivica-novakovic.from.hr/LedSensor-eng.htm
__________________
Gayan

My Website
http://gsmicro.blogspot.com/

Last edited by Gayan Soyza; 18th August 2008 at 06:49 AM.
Gayan Soyza is offline  
Old 18th August 2008, 02:04 PM   (permalink)
Default

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.
Mike, K8LH is offline  
Old 18th August 2008, 02:23 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
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
Hi Mike,
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.
Attached Images
File Type: gif LED_Light1.gif (17.7 KB, 13 views)
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 18th August 2008, 02:24 PM   (permalink)
Default

This LED sensor stuff is interesting, going to give it a go on a Junebug.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline  
Old 18th August 2008, 02:42 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics View Post
This LED sensor stuff is interesting, going to give it a go on a Junebug.
hi Bill,
This plot is with 3 RED leds in series.
Attached Images
File Type: gif LED_Light2.gif (17.4 KB, 12 views)
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 18th August 2008, 02:42 PM   (permalink)
Default

Hi Eric,

Thanks for info'. Looks very nice on your analog logger.

Mike
Mike, K8LH is offline  
Old 18th August 2008, 02:48 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
Hi Eric,

Thanks for info'. Looks very nice on your analog logger.

Mike
hi Mike,
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.
ericgibbs is offline  
Old 18th August 2008, 03:44 PM   (permalink)
Default

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.
Mike, K8LH is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
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



All times are GMT. The time now is 04:05 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker