Shop OBEX P1 Docs P2 Docs Learn Events
How to avoid sinking/sourcing much — Parallax Forums

How to avoid sinking/sourcing much

alexopricealexoprice Posts: 20
edited 2005-02-10 14:16 in BASIC Stamp
I want to power a 1.7 volt, 20ma (3000mcd) LED somehow from my board of education. I want it to go on when it is dark and go iff when it gets bright. Here is the code i am using now -

DO
IF IN15=0 THEN LOW 5 ELSEIF IN15=1 THEN HIGH 5· ' pin 15 is the input of my photoresistor
LOOP

I think the documentation says that max sink is 25ma and max source is 20ma, and i am right on the edge there. Without decreasing the power to my LED, i would like to keep using this without harming my bs2. IS there any way to do this using just Vdd and Vss and the BS2 to power it some how?

Thanks for your help

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-02-04 00:43
    You're pushing a lot of current through one pin -- would be better to add a transistor buffer; the transistor (e.g, 2N3904 or similar) and a couple resistors (one for the base current, the other for the LED current) would cost less than a dollar and protect the BASIC Stamp while running the LED full-throttle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • alexopricealexoprice Posts: 20
    edited 2005-02-04 01:20
    thanks a lot
  • achilles03achilles03 Posts: 247
    edited 2005-02-04 02:33
    Or just put a 470 ohm resistor. It won't be as bright, but it'll work ok.

    On a side note, the code you wrote isn't in the right form. It's:

    IF (condition) THEN (label)

    I don't know if you just wanted to show your general idea... just FYI.

    Dave
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-02-04 15:08
    The current through a device is the 'dependent' quantity. It depends on the voltage and resistance YOU PUT into the circuit. If you don't put it in, the current can be quite high -- destructively quite high. The voltage for BS2 circuits is usually fixed at 5 volts. Thus, the only thing you have control over to limit the current is the resistance.

    When an LED says it's 1.7 volts, 20 mA, that means that when it is on it drops 1.7 volts across itself (independent of current), and the max current it will take without destruction is 20 mA. This means you MUST put a resistor in there to limit the current.

    When the BS2 says it can sink or source 20 (or 25) mA, that's how much it can do without destroying the drivers behind that pin, inside the chip. Again, there's nothing limiting the current except the resistance you put in there.

    The voltage equation is Ohm's Law: V = IR, or Volts = Current times Resistance. Thus I = V/R. The typical equation for finding the current through an LED is:

    (Total_Voltage - LED_Voltage) / Resistance == Current, or (Total_Volts - LED_Volts) / Current == Needed_Resistance
    ( 5 Volts - 1.7 Volts) / 15 mA == 220 ohms.

    Now, you need to know that the brightness of an LED varies depending on the current through it. It won't come on at ALL if it doesn't have at least 1.7 volts across it. After that, it's the current. You'll have to do some experiments to find the minimum current that lights the LED. An LED that will take 20 mA max will probably turn on completely with 10 mA -- 15 mA should be a very good value.

    P.S. if you DO connect a BS2 pin to an LED, and the other end of the LED to +5, and you don't put a resistor in series with the circuit to limit the current, THEN when you make the BS2 pin an OUTPUT LOW either the LED will flash once and die, or the BS2 pin will try to drive too much current and burn itself out (permanently), or both.· If you tie the other end of the LED to ground, then the same thing can happen when you make the BS2 pin an OUTPUT HIGH.

    Everybody has probably done this more than once, by the way, while learning.· I've not done this to a BS2, so I don't know what dies first.· I would hope it's the LED.




    Post Edited (allanlane5) : 2/4/2005 3:19:19 PM GMT
  • Pinoy NYCPinoy NYC Posts: 30
    edited 2005-02-10 04:59
    Hi Jon,

    Can you explain more?
    I'm not an expert in electronics, I still consider myself a newbie.

    You mentioned about using a transistor buffer, are you referring to a transistor like TIP120 where BS2 will switch on the LED through the base of this transistor?

    Or a 74LS245· which is sometimes reffered to as a buffer, which is most people claim will protect their circuit?

    I saw the use of this buffer in this circuit.
    http://www.q1.fcen.uba.ar/materias/iqi/paralel1/et.nmsu.edu/~etti/winter97/computers/logic/logic.html

    > You're pushing a lot of current through one pin -- would be better to add a transistor buffer; the transistor
    > (e.g, 2N3904 or similar) and a couple resistors (one for the base current, the other for the LED current)
    > would cost less than a dollar and protect the BASIC Stamp while running the LED full-throttle.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-02-10 13:57
    I tend to keep things simple -- you were talking about driving a single LED so a single transistor (or Darlington) buffer circuit seems appropriate.· The attached schematic shows a typical setup.· With a 470 ohm base resistor you should get about 9 mA into the transistor (will be a little less with a Darlington); this should drive the transistor into saturation (make it act like a switch).· There will be a small voltage drop across the transistor (emitter to collector), so you'll have to size your LED resistor accounting for that and your LED supply voltage.

    I appreciate that you're new at electronics -- we've all been there.· That said, let me encourage you to be very careful and not take shortcuts.· You BASIC Stamp was expensive and you could easily damage it by connecting an improperly designed circuit.· There are lots of great electronics books out them, from very simple ("Getting Started in Electronics" by Mimms) to very sophisticated ("The Art of Electronics" by Horowitz).· I've posted Amazon links for your convenience.

    http://www.amazon.com/exec/obidos/ASIN/0945053282/qid=1108043764/sr=2-1/ref=pd_ka_b_2_1/104-7974495-2692734
    http://www.amazon.com/exec/obidos/ASIN/0521370957/qid=1108043835/sr=2-1/ref=pd_ka_b_2_1/104-7974495-2692734

    Good luck with your projects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-02-10 14:16
    Yes, and the keys to not damaging a pin on the BS2 is:

    1. Make sure there is enough resistance on the pin (you add this with resistors) so (V=IR, I = V/R, +5 / R == I) +5 volts / Resistance is ALWAYS less than 20 mA. The Homework Board comes with 220 ohm resistors on each pin to guarantee this.

    2. Only set pins as OUTPUT that you want to use as OUTPUT. It's very hard to damage a pin which is set as INPUT. INPUT is the default state of all pins on power-up.
Sign In or Register to comment.