PICAXE 08M questions about LED control

hokieed

New Member
I am using a picaxe 08M with a 4.5 volt supply. I am trying to fade an array of LEDS when a finger passes over a sensor in a lit room. Here is my progress so far.

I have so far succeeded in using an LDR to notice a finger passing by, and I can make one LED fade out in the time I like. Now, how do I get an array of LED's to do that?

Here is the circuit I have right now. Do you see any problems with it?


4.5v --------o-----------------o
| |
| |
-------- LDR
| 08M | |
| | |
| | (in 1) |
(out4)o--|3 6|--------------o
| | | |
| | | |
| -------- |
| | |
330ohm | 1k ohm
| | |
| | |
1.7v | |
20mA LED | |
| | |
| | |
0v --o------o-----------------o


Is there any reason why I would need a larger resistor for the LDR comparison other than changing the sensitivity?


I like how simple the circuit is right now, since I need about 10 of them.

The circuit works really well right now, being very sensitive to even a very fast moving finger over the LDR.


Here is the code I am using:


main: readadc 1,b1
if b1<50 then flash
goto main

flash:
for b2 = 1 to 40
b3 = b2 * 5
b4 = 201 - b3
pwm 4,b4,3
next b2
goto main



I start the pwm signal at 201 so the brightness is just right and the fade looks good.
The increment size of 5 gives me a good fade.
Was I right to assume the pwm output cannot be zero?



So, now that this seems to be working well, how do I get an array of LED's, 8 to 10 of them, to fade at the same rate, on command?


Sice my background is all things mechanical, I am very new to elecrtonic circuits and the picaxe. Any help to get me in the right direction will be greatly appreciated. Thanks!

Eddie

 

hokieed

New Member
wow! that circuit diagram didnt come out right at all. It looked good in the message window. :-( Hmm, let me try a differnet method.
 

hokieed

New Member
here is a scanned drawing of the simple circuit:

http://www.eddiesmind.com/pictures/temp/08Mquestion.jpg

Thanks again
 

BeanieBots

Moderator
The PICAXE can only supply about 20mA from each pin, so if you want to drive 10 LEDs you will need a transistor. See the interfacing circuits in the manual for details.
With 4.5v it should be possible to run two LEDs in series (not blue or white). Thus each output could run two, using 4 outputs would give 8 LEDs. This would be very close to the total maximum for the chip so I would have to advise against it but should be OK.

Changing the 1k resistor will change sensitivity and range. The 'best' value to use is the one that gives the response you want. In other words, experiment to find the best value for YOUR application.

Have a look at the "forum protocol" tab to see how to post ASCII art and/or formatted code.

Edited by - beaniebots on 26/04/2007 20:24:19
 

hokieed

New Member
Here is a clickable link:

<A href='http://www.eddiesmind.com/pictures/temp/08Mquestion.jpg' Target=_Blank>External Web Link</a>


So, I looked at manual3. I haven't used transistors before, so I'll give it a go. Will the BCX38B work fine for me, and will it still allow the pwm signal to go to all of the LEDs? For some reason, I always though transistors were just on/off.

Can I buy a BCX38B at a store like Radio Shack?

 

BeanieBots

Moderator
Transistors are not just on/off but for your application you actually want it to be just on/off by using it in the mode as described in the manual. The PWM will turn the transistor on/off which in turn will turn the LEDs on/off giving the desired dim effect.
 

GregLink

New Member
A personal favorite chip is the ULN2x03 series (such as ULN2803) driver array. 8 outputs, that can each handle reasonable current, and easy enough to buy anywhere for cheap. (Jameco has them for 47 cents each)

Useful for many projects, I always keep a dozen or more on hand.

 

hokieed

New Member
Duh! pwm is just an on/off signal of varying length. So I see how the transistor would work now. Can you see the light going on (and off) over my head?

 

Mycroft2152

Senior Member
Almost any small signa; NPN tansistor will work, 2N2222 or 2N3904 ( os is it the 2N3906?). In the US the 2N---- transitors are more common.
 
Top