Simplest dark sensing LED flasher

wilf_nv

Senior Member
#1
Simple is as simple does and it doesn't get any simpler than this.

<A href='http://www.user.dccnet.com/wrigter/picaxe/darksensingLEDflasher.gif' Target=_Blank>External Web Link</a>

Flashes LED when very dark. Easily detects the presence of a RED LED emitter across a dark room. Several of these dark flashers in a dark room interact quite nicely in complex ways. Tested with an 08M but should work fine with an PicAxe 08. Standby current when light is 80uA and in the dark, while the LED flashes with 10% dutycycle, the average current is 500uA.

No LED resistor? You do the math.

wilf


Edited by - wilf_nv on 17/01/2007 06:06:19
 
#2
That is cunning.

I remember once seeing a mathematical explanation of why a group of fireflies end up flashing in synchrony. With a lot of these circuits and a bit more code to adjust the delays it might be fun to explore...
 
#3
Ummm, I want to do the math, but I don't know what I should be adding or subtracting (or multiplying or dividing)!

So, ummm, why no LED resistor again? :)
 
#4
(Vcc-Von_led)/(IOsource_Z+IOsink_Z) for peek I
X duty for average I

IOsource_Z and IOsink_Z are the output impedances of the PICAXE IO lines for each state. These can be found in the PIC datasheet and will also be a function of the supply voltage. Then multiply by the on/off duty cycle to get an average current draw.
 

wilf_nv

Senior Member
#5
&quot;So, ummm, why no LED resistor again&quot;

Because to be the simplest flasher, it should have the fewest components and in this case we can eliminate the LED resistor if the current can be limited by the internal resistance of the two picaxe outputs at the maximum supply voltage of interest (4.5V).

We must try not to exceed the maximum load current for the 08M picaxe outputs which is 25mA per pin.

The maximum current flows when the LED is on.

I measured the average current using a multimeter as 500uA and the dutycycle of the flashing LED is 1/10.

For simplicity, we can ignore the Picaxe quiescent supply current and assume that all the measured current flows through the two outputs connected in series with the LED.

Given those values, the peak output current during the time that the LED is on must be Iavg/dutycycle = 5ma.

This does not exceed the max output current so we can get away with no LED resistor for this particular application.

wilf

Edited by - wilf_nv on 18/01/2007 20:55:39
 

manuka

Senior Member
#6
Well done! This is super tempting to take further as an educational stimulator, since it'd quickly get kids curiosity going &amp; motivate them to investigate the background. See the likes of <A href='http://mvh.sr.unh.edu/mvhinvestigations/light_investigations.htm ' Target=_Blank>External Web Link</a> Interested?

You've jogged my memory over a long standing interest in LED based light detection,with even IR types being capable of such persuasion. Naturally the effect of using different colour LEDs spring to mind in your bare bones flasher. Now where's that breadboard... Stan
 

premelec

Senior Member
#7
Hi Wilf - I admire your search for minimalist functionality! I wonder if you have _measured_ the peak current [say with a 1 ohm resistor in series with LED and scope] occuring when run with a hard power supply?

I have gotten a similar effect with a soft power supply so that when an LED turns on it forces a reset of the PICAXE... :-0
 

wilf_nv

Senior Member
#8
Thanks,

my mission in technology is to do more with less and ultimately, by reductio ad absurdum, to do everything with nothing. 8^)

One factor I have not fully investigated is reduced &quot;short circuit&quot; output current while the 08M is in the NAP mode which is the case here used to conserve power.

I will measure the peak current in the normal mode and in the NAP mode with my DSO and report the results.


Edited by - wilf_nv on 18/01/2007 23:11:44
 

manuka

Senior Member
#9
Well this certainly works OK, but the LED type seems quite crucial,as some reds here just would not illuminate at all. All whites to hand (typically ex. cheapo solar garden lamps)gave a superb performance however, as did my favourite &quot;Jaycar Blue&quot;. As whites have a yellowy phosphor dollop on their underlying blue LED, PV performance is often only modest.

Out of interest, &amp; since the down under summer sun is at it's obliging best, I exposed several LEDs outdoors &amp; recorded their resulting &quot;PV&quot; reading on a DMM.

Colour ~bright sun voltage (unloaded)
--------------------------------------------
Clear green 1.6V
Frosted yellow 1.5V
White &gt; 1V
IR 0.8V
Frosted blue 0.8V
Plain red 0.2V

LED responsiveness to illumination changes was most striking, although the IR LED readings remained much more constant as this varied, perhaps due to nearby thermal sources (shielding hands etc) as well.

We're in a fascinating era for LED lighting applications, so further work as dual purpose sensors sensors may be very productive - &amp; fun!
 
#10
I did a similar test to Manuka's on a few LED's of different colours, looking for sensors to use on a solar tracker, and the yellow and green LED's were the outright winners. Red LED's barely produced a few millivolts.

Solar tracker central: <A href='http://www.redrok.com/main.htm' Target=_Blank>External Web Link</a>.
 

wilf_nv

Senior Member
#11
Hi Jo,

In the flasher application it is the LED photo leakage current that is exploited (photoresistor).

It is not just the LED color but the semiconductor compound used that determines the PV output.

When measuring the LED PV output, its low output current and loading by the DVM input resistance (10M) can result in an apparently low output voltage. You need a fet opamp buffer to more accurately measure the &quot;open circuit&quot; output voltage.

wilf
 

wilf_nv

Senior Member
#12
<i>I have gotten a similar effect with a soft power supply so that when an LED turns on it forces a reset of the PICAXE... :-0 </i>

Thanks for that premelec!

The brown out detector will reset the chip if Vcc dipped momentarily below the threshold when the supply is soft and the load current sufficiently high.

In fact, this turns out to be a problem with this circuit too if the 4.5V battery runs down just a little. To fix this, I humbly suggest adding a 100 ohm resistor in series with the LED. The resistor should be connected on the cathode side to avoid adding stray capacitance to the sensing anode side.

Albert Einstein
Everything should be made as simple as possible, but not simpler.

 

premelec

Senior Member
#13
I made a unit with an 08M I/O pin watching for voltage from an LED reading it with ADC and then using the same pin to flash the LED.

It needed to have bypass cap and a little R added in parallel to the LED or it was very unpredictable [essentially an open input pin]. Eventually I changed to an LDR for the light sensing - but you have used the LED differently... interesting...
 
#14
G'day Wilf,

I have a fet opamp in my drawer, so I will have another go at my LED PV measurements.

I have the flasher circuit up and running with the nearest red LED to hand. Very nifty.

I'm probably the only one who doesn't see how this works, so just to check my understanding:

When the 'anode' pin is tristated the leakage current through the LED discharges its internal capacitance, and the voltage at the anode rises toward the high cathode voltage. (I hope).

The 'pin2 = pin2 xor 1' statement checks the state of the input voltage and, essentially, sets the output state of pin2 to the opposite of this.

Interesting that you can set the future output state of a pin before it becomes an output. Is this the same thing as on some tristatable chips (the 74HC374 springs to mind after its recent outing) where an output register can be set before the output is actually enabled?

I find this very interesting.

Manuka: very nice link. Thanks for that.

Cheers.

 

wilf_nv

Senior Member
#15
You've got it Jo. Just like the 4096 LEDs controlled by the 374 octal flipflop.

In the sensing mode, the voltage rises on the LED anode while discharging its capacitance to Vcc (cathode) when picaxe PIN2 is set to input mode. After a delay (threshold), I store the voltage at input PIN2, inverted, to the register for output PIN2. When PIN2 is set to output mode and the cathode is pulled low, the LED displays the state of the PIN2 output register.

For this dark sensing application, the relatively long time interval for delay (threshold) is set slightly shorter than the time for the LED to discharge the &lt;100pf capacitance at the anode in the dark. The capacitance must be kept small or the discharge time will be very long, so the LED must be located close to the chip.

wilf


Edited by - wilf_nv on 19/01/2007 15:40:17
 

wilf_nv

Senior Member
#17
It is good practice to terminate all unused cmos inputs by connecting them either high or low. If the input is left unconnected and floating, it can cause oscillations, increase power supply current and is more vulnerable to damage from static discharge.

Unused bidirectional pins that are normally initialized as inputs at power up, should be set to output and left unconnected.
 

manuka

Senior Member
#19
LED photo-leakage current! Apologies- I'd not sufficiently scrutinised the code &amp; had quite overlooked this LED facit. This is currently a much researched TFT topic, but at the grass roots level may even allow a LED colour dependant &quot;Poor Man's LDR &quot;.

For those after a further &quot;One LED wonder&quot; challenge, try tweaking the initial code so the LED flashing is controlled by READADC! Stan
 

geoff07

Senior Member
#20
Really neat and elegant! I just built one in 10 mins using a picaxe proto board and one led and it is very amusing. I wonder how many people realise a led is also a pv device? I didn't.

Any ideas for an economical but physically small battery? Three AA cells look gigantic in this context.
 
#21
I built this also and was astonished by the sensitivity of the single led. It could &quot;see&quot; a red plastic coated neon light in a power strip from across the room and stay in the off state.
 

wilf_nv

Senior Member
#22
just a reminder that in this circuit the LED is used as a reverse biased photo diode like a light dependent resistor. This LED photo resistor, together with its own junction and stray capacitance, forms an RCTIME type circuit that is used to measure variations in LED photo resistance.

wilf


Edited by - wilf_nv on 21/01/2007 23:08:59
 

manuka

Senior Member
#25
Lovely! For those yet to view the link it shows a &quot;touch responsive&quot; 8x8 LED matrix. I'm now wondering if IR LEDs would suit as sensors as well?
 

lbenson

Senior Member
#27
Wilf--I used your code and circuit with ADC to read the voltage off of an LED. I got very good range of response with a yellow LED to ambient interior lighting, with more or less shading from my hand, and with a flashlight for increased response. I'd like to extend this to see if a solar tracker can be made with 3 leds in a triangular pattern, perhaps with some shielding of the led to make it more directional. There aren't enough pins on the 08M. I have an 18X--is there a circuit such that that part can be used, even tho you can't switch the pins between input and output? Or is there a not-too-difficult extension which would enable the 08M to do it? My programming experience is extensive, but electronics knowledge is rudimentary at best.
 
#30
Treat this suggestion with caution because I may be being stupid here but can't you connect all 3 LEDs to a common pin (anode) and then control the cathode on 3 other pins?
 

wilf_nv

Senior Member
#31
Yes, the 08M can be used with two LED sensors to make a differential measurement using this RCTIME technique.

The code is different from the simple flasher which used a fixed threshold (minimum RCtime constant) for reference.

The differential light measurement for solar tracking should detect which LED sensor has the shorter RC time constant to determine which has the brightest illumination.

Since the conversion generally takes several tens of miliseconds or more a software timer can be used to measure the TCs and determine the difference value.

The Picaxe inputs must have very low input leakage current and low capacitance to work with LED sensors. Of the 3 bidirectional pins one is not suitable as an input for LED sensors (I'm at work so I can't confirm which until later)

Similarly, hippy reported that he had no luck using the ADC function with LED sensors probably because the ADC module has a 120pf holding cap that must be charged from the input source.

The literature suggests a maximum 30K source impedance to avoid errors. That is 3 or 4 orders of magnitude smaller than the LED sensor source impedance.

Temporarily lowering the Picaxe clock frequency to 32KHz or less may allow the A/D conversion process to slow down enough to adapt to very high impedance sensors, like the LED sensors.


Hmmm... scratch that idea. After looking at the microchip 12F683 data (08M), it appears that the ADC oscillator can't be slowed that much. In any case, note the leakage current at the ADC pin is 500nA which is large compared to the LED photo current.

I think I know why you can't use the ADC with a LED sensor.


Edited by - wilf_nv on 29/01/2007 23:51:46
 

lbenson

Senior Member
#32
&quot;I think I know why you can't use the ADC with a LED sensor&quot; -- wilf

Do you mean with other than an 08M? With the cathode of a yellow led tied to pin1 through a 330 ohm resister, and the anode tied to pin2, I used the following program:

<code><pre><font size=2 face='Courier'>
' TEST06 led as light detector (yellow led)
' ___ LED
' pin1- -|___|-----|&lt;--.
' 330 |
' pin2- ---------------'

symbol cathode=1
symbol anode=2
high anode ' flash test led
low cathode
pause 100
low anode

main:
high cathode
low anode
input anode ' tristate anode (isolate anode pin)
nap 7 ' nap 2 sec
readadc anode, b2 ' get the voltage
low cathode ' pulse cathode
nap 3
b4 = b2
b5 = 0
w2 = w2 * 45 / 255 ' x = 4.5V * adcVal /255
b6 = w2 / 10 ' whole volts
b7 = w2 % 10 ' tenths of a volt
sertxd (&quot;ADC value: &quot;, #b2, &quot;; LED voltage*10: &quot;, #w2, &quot;; &quot;, #b6, &quot;.&quot;, #b7, &quot;volts&quot;,13,10)
sleep 1 ' sleep 1 sec
goto main
</font></pre></code>

and got the following results (I added the comments):

<code><pre><font size=2 face='Courier'>
ADC value: 0; LED voltage*10: 0; 0.0volts ' totally covered
ADC value: 89; LED voltage*10: 15; 1.5volts ' covering reduced
ADC value: 158; LED voltage*10: 27; 2.7volts
ADC value: 164; LED voltage*10: 28; 2.8volts ' ambient interior lighting
ADC value: 255; LED voltage*10: 45; 4.5volts ' flashlight on
ADC value: 255; LED voltage*10: 45; 4.5volts
ADC value: 172; LED voltage*10: 30; 3.0volts ' flashlight pulled away
ADC value: 172; LED voltage*10: 30; 3.0volts ' about a foot away
ADC value: 225; LED voltage*10: 39; 3.9volts ' back to 2 inches away
ADC value: 162; LED voltage*10: 28; 2.8volts ' flashlight off--ambient lighting
ADC value: 55; LED voltage*10: 9; 0.9volts ' partly covered
ADC value: 0; LED voltage*10: 0; 0.0volts ' totally covered
</font></pre></code>
 

hippy

Technical Support
Staff member
#33
<i>&quot;Poke $AE,$xx&quot; will control the direction of the 18X output pins, 1=Input/0=Output ... Once set as input, how do you read them? </i>

To read the pins, read the PORTB register with &quot;Peek $06,var&quot;. You can only read all pins as a byte, but use &quot;Peek $06,b0&quot; and then use 'bitX' variables to test single pins.
 

wilf_nv

Senior Member
#35
<i>&quot;I think I know why you can't use the ADC with a LED sensor&quot; -- wilf

Do you mean with other than an 08M? - Ibenson
</i>

Very interesting! Instead of a 1 bit A/D conversion by testing if the voltage of a decaying R/C discharge waveform is greater or less than the the logic threshold of the Picaxe input, you have combined this with READADC to measure the actual value on the slope at that time. That way you get a quantitative value instead of a logic level.

Should be easy to test this conjecture by varying the interval between INPUT ANODE and READADC ANODE. If the readings are higher values for longer intervals, then the measurement is a point on the R/C discharge slope.

Unfortunately no time to test this myself until later, but looks very promising as a new measurement technique.

Edited by - wilf_nv on 30/01/2007 16:02:09
 

lbenson

Senior Member
#36
To investigate the idea that the program and circuit above is testing the voltage of a decaying R/C discharge waveform, I did the readadc 4 times, with naps between each read. Values of the nap parameter up to the full range (~2 seconds) made no difference in the reading, which continued to run the full range from 0 to 255 depending on whether the LED was completely shadowed, exposed to ambient interior lighting, or to a flashlight at distances from 12 to 2 inches (maximum 255 reading).

Interestingly, the reading with the flashlight was very sensitive to its placement&#8212;at right angles, it produced little difference from the ambient lighting reading, and the difference increased as the flashlight moved to directly over the led. That means that the LED is directional in itself without the need for side shielding.

I then commented out the first two lines in the &#8220;main&#8221; routine, &#8220;high cathode&#8221; and &#8220;low anode&#8221;. This greatly reduced the range of the ADC reading, from 0 when occluded to 38 in ambient lighting to 80 when the flashlight (an LED type) was directly above and about a quarter inch away.

I then removed the 330 ohm resister. This made no significant difference in the reading. I then stripped down the original code so there is no &#8220;reverse biasing&#8221; of the led. There was no great change in the responsiveness of the LED. Moving the circuit so that it was more and less directly pointing at a 60 watt bulb increased and decreased the ADC reading in an expected manner.

So it appears that the reverse biasing increases the range of response but is not crucial for the effect. It appears that an 08M with a single yellow LED could track the sun or other moving light source. Please note that my electronics knowledge is very limited, so any of this is subject to correction and especially, more precise explanation.

<code><pre><font size=2 face='Courier'>
' TEST06D led as light detector (yellow led)--08M
' LED
' pin1- ------|&lt;--.
' |
' pin2- ----------'

symbol cathode=1
symbol anode=2
high anode ' flash test led
low cathode
pause 100
low anode
input anode ' tristate anode (isolate anode pin)

main:
readadc anode, b0 ' get the voltage
gosub printReading ' b0 contains ADC value to be displayed
sleep 3 ' sleep 3 sec
goto main

printReading:
b4 = b0
b5 = 0
w2 = w2 * 45 / 255 ' x = 4.5V * adcVal /255
b6 = w2 / 10 ' whole volts
b7 = w2 % 10 ' tenths of a volt
sertxd (&quot;ADCval=&quot;, #b0, &quot;; LED voltage*10=&quot;, #w2, &quot;; &quot;, #b6, &quot;.&quot;, #b7, &quot;volts&quot;,13,10)
return
</font></pre></code>
 

lbenson

Senior Member
#37
A green LED gave slightly higher ADC values&#8212;86 vs 80 for a max with the flashlight, and 41 vs 35 for the ambient room lighting. Red gave lower still&#8212;68 for a max and 12 for the ambient lighting. Still waiting for sunshine.
 

lbenson

Senior Member
#38
Performance of the LED in direct sunlight was disappointing, at least initially. For a Green LED the range between shaded and pointed directly at the sun was only from 83 to 90, which would make steering towards the sun somewhat dicy. With a red LED the range was from 68 to 75, and with yellow from 77 to 84. The good news is that the peeks corresponded with pointing at the sun, and the dips with pointing away. Perhaps putting the LED in a small dark tube would help.
 
#39
LEDs have differing 'viewing angles' based on their construction geometry. So the reverse is true for light direction sensitivity. Adding tubes around the LED or even painting the sides would help.

For anything you've always wanted to know about LEDs, but were afraid to ask -- visit the LED Museum <A href='http://ledmuseum.home.att.net/' Target=_Blank>External Web Link</a>

There is some 'enlightening' stuff there ;)
 

wilf_nv

Senior Member
#40
Ibenson - I think you are observing two distinct photo effects:

1) photo leakage generated reverse current
2) photo voltaic generated forward voltage

The method of allowing the LED to discharge its own reverse biased junction (and stray) capacitance is based on photo leakage current.

Photo leakage current is a linearly proportional to light level and reverse bias voltage.
For LEDs reverse biased at 5V the maximum photo leakage current in full sunshine varies but is generally less than a few microamp.

The photovoltaic effect is a log function of light level with the maximum voltage limited by the intrinsic or barrier voltage of the semiconductor materials.

In your latest test code you measure the LED voltage rather then the photo leakage and the different results for different LED colors correspond to different semiconductor materials.

The short circuit photo current of the LED generated by the photovoltaic effect is even smaller than the reverse photo leakage current by a factor of 3 or 4. Even the 10M input resistance of a DVM will load the LED and reduce its photovoltaic output voltage.

Still somewhat speculative, I will try to confirm this model of your test results when I get to my lab bench.

wilf
 
Top