I'm new to hobby electronics and I have a few questions surrounding an upcoming project. I'm trying to build a circuit that fades one set of three LEDs to another set of three LEDs (back and forth). I've decided to use an ATtiny45 microcontroller (programmed with my Arduino UNO) and I've put together a wiring diagram to make sure I'm thinking about this circuit correctly (see attachment).
Circuit Specs
Voltage: 4.5V DC
LED Voltage Drop: 3.4V
LED Current Max Current: 20mA
Microcontroller: ATtiny45
Here are my questions:
Is this circuit is wired correctly (see attachment)?
How do I choose the right transistors to buy (and how to know why they're rated correctly for this circuit)?
Do I need resistors between the PWM pin and the transistor?
Any help is greatly appreciated! I have much to learn.
It looks quite correct, except that you do need resistors between the PWM pins and the transistors (which answers question nr. 3, the value of the resistor isn't very vital, it is just needed to protect the output pin, but should be small enough to let the transistor to switch fully on).
You can pretty much use any general-purpose NPN-transistor for this, as long as it can switch the required current, which you can simply calculate using Ohm's law (U=R*I). So I = U/R = 4.5/(56/3) = 0.241 A = 241 mA. So the common 2N3904 isn't enough, but the equally popular 2N2222 is powerful enough.
Another type of transistor that would work in a scenario like this is the logic-level mosfet, a mosfet that switch fully on with only logic-level voltages. This would eliminate the need for input resistors.
If using NPN transistors your load LED and series resistor should be in the collector circuit and the emitter lead grounded, this will allow better bias control on the base which as already stated requires a series resistor between the base and the output pin.
Generally one uses NPN and N-Channel MOSFET to sink current from a source to Ground, vs sourcing current into a load - that is, put the LED/resistor between 4.5V & the NPN collector, with the emitter to gnd/battery.
How much current did you want in the LEDs?
(4.5V (Vs) - 0.7V (Vce) - 3.4 (Vf))/56 = ~7mA
Thank you all very much for the information! That's exactly what I needed to know.
CrossRoads: I think the LEDs should be at 20mA for maximum brightness. Do I need to reduce that number to make sure I don't blow the LEDs -- especially when fading between the two sets?
Re-do the math. Its just Ohms Law, Voltage (V) = Current (I) * Resistance (R), V=IR.
Rearrange to suit your needs: V/I = R, V/R = I
In this case, we are solving for the voltage across the current limit resistor: Vsource - Vled - Vtransistor = Vresistor.
Knowing, you can calculate the resistance needed to obtain a selected current: Vresistor/Idesired = Rneeded
(4.5V (Vs) - 0.7V (Vce) - 3.4 (Vf))/56 = ~7mA
Plug in your details and calculate away. 22, 27 are standard values for resistors, use those if you have a collection of standard values.
(4.5V (Vs) - 0.7V (Vce) - 3.4 (Vf))/22 = 18.2mA Close enough to 20mA for me.
CrossRoads: Yep, that makes sense. I didn't account for the current from the transistor in my initial diagram, so that will be good to know going forward.