Electronic – arduino – 9-volt battery connected to transistor controlling LEDs with Arduino

arduinobreadboardledtransistors

I am trying to add a custom LED lighting setup to my desktop gaming computer. In this setup I want small sets of LEDs to be able to be turned on separate of other sets. This is so that I can turn on different sets at different times to make a "light show".

I am using an Arduino's digital I/O pins to control a transistor (BC547B) which will supply power from a 9-volt battery to the LEDs. The LEDs are rated at 1.9v and I have multiple sets of 5 LEDs (5 * 1.9 = 9.5 — no need for a resistor… right?) connected in series and those "multiple sets" are to be connected in parallel.

However, due to a simple lack of transistors, I am temperarily (until I get more transistors) connecting 2 sets of the 5 LEDs per transistor. Confused? Let me put this together in a schematic using only 1 transistor (in the final version there will be more):

schematic

simulate this circuit – Schematic created using CircuitLab

So, basically the problem is, when I turn on pin 5 on my Arduino, the LEDs do not light up. Why is this?. I may be doing something wrong here, but, if I am, I cannot figure it out.

Here is the temporary code for the Arduino I am using, just in case someone wants to see it:

void setup() {
    pinMode(5, OUTPUT);
}

void loop() {
    digitalWrite(5, HIGH);
    delay(1000);
    digitalWrite(5, LOW);
    delay(1000);
}

All it does is turn pin 5 on, wait a second, turn it off, wait a second, and repeat.

Thanks in advance.

P.S. Apologies for awkward title.

EDIT:

I should also note that I'm very new to this kind of stuff. I'm doing this for a sort of learning project (and so my computer can look cool).

Best Answer

First off, the whole "5*1.9V = 9.5V -> no need for a resistor" isn't going to work. The forward voltage is not exact, and neither is your 9V. Here's an explanation of why forward voltage == supply voltage is an issue. Also, there's going to be some voltage drop across your transistor.

Your circuit has many issues.

  1. To turn on the transistor, the Arduino would need to output 5*1.9V + ~0.7V = ~10.2V. The Arduino pins output 5V, so that's a no go right off the bat. If you ground the emitter and connect the LEDs to the collector, that's much more likely to work.

  2. Your transistor needs a base resistor to limit current through it. You risk damaging your Arduino and your transistor. When saturating the transistor (which is what you want to do to get it to act like a switch), the base will be at ~0.7V. Without a base resistor, the Arduino pin drives that to 5V and a whole lot of current flows into the base, burninating the poor Arduino. Hence, a base resistor is required; its value is dependent on how much current you want through the LEDs and the current gain of the transistor. Without doing the math, something between 220Ω and 1kΩ is probably good.

  3. LEDs or LED strands in parallel need individual resistors. There are many answers on this site that can explain why in greater detail; basically, the net forward voltage across different LED strands will differ, causing current imbalance. Mathematically, \$\frac{V_s-nV_f}{I_f} = R\$, where \$V_s\$ is your supply voltage, \$n\$ is the number of LEDs in a series strand and \$V_f, I_f\$ are the LED forward voltage and desired forward current, respectively.

  4. When you do get this working, your 9V battery probably won't be adequate (9V batteries have very little capacity and low current capability). A 9V wall wart or similar would be much more appropriate. Also, that transistor is only rated for a maximum of 100mA collector current. A few LED strands will exceed that and your transistor will be toast. A bigger transistor, or better yet, a nice beefy MOSFET, will ensure you can safely switch many LEDs. For a single strand, or maybe two, that transistor is fine. If you are using a 12V PC PSU, that's fine, just make sure to calculate your current limiting resistors with 12V instead of 9V.

So, use four LEDs in series and an appropriate current limiting resistor, change the connections of the transistor, and add a base resistor. That should at least get you started.