I have zero experience with electronics, never played with it before last christmas, when I got an Arduino starter kit.
From reading around the forums here, I gathered that you can damage the Arduino when drawing too much current, putting voltage on output pins, exposure to negative voltage, damage LEDs by applying too much voltage, damage transistors in all kinds of ways.
The transistors are BC547B PNP that came with the kit.
D0 and D1 are connected to Arduino digital output pins.
The power rail is connected to the +5 and GND on the Arduino.
The idea is that for each combination I put on D0 and D1, one of the LEDs lights up:
00 = LED1, 01 = LED2, 10 = LED3, 11 = LED4, and the other 3 are off.
This works, but I can't tell whether it does bad stuff and will eventually burn through the pins, the LEDs or the transistors.
So I have 2 questions:
Is this circuit dangerous/harmful for any of the components, especially for the Arduino?
What would be a good way/place to educate myself a bit on this matter?
EDIT: Correction - those transistors are in fact NPN.
With the resistors (220K or more) in series with the outputs to limit the current, and with +5V or less applied (and with no negative voltage), you can't damage your Arduino. Your transistors look safe too, although I haven't thoroughly analyzed your circuit.
You do have to be careful with resistors in parallel because each resistor (and other associated circuitry) provides a current path. For example, ten 220 Ohm resistors in parallel is the equivalent of 22 Ohms, and that would be too much current from an Arduino pin.
The idea is that for each combination I put on D0 and D1, one of the LEDs lights up:
00 = LED1, 01 = LED2, 10 = LED3, 11 = LED4, and the other 3 are off.
That can be done in software (with if-statements, or perhaps with switch-case logic). So, you'd just need two Arduino outputs with an LED (and current limiting resistor) on each output pin.
If you wanted to do it in hardware, you'd normally use [u]logic gates[/u] (and-gates, or-gates, etc.) rather than trying to design your own logic circuitry with transistors.
The exception would be a [u]wired-or[/u] connection where two (or more) transistors are wired in a way such that either (or any) transistor can turn-on and pull-down a signal.
You overload D0 and D1 since they each drive several 220's in parallel, drawing too much current.
Pins D0 and D1 are connected to the USB serial chip, using them for other stuff is usually a mistake.
You are shunt-switching the LEDs by shorting out across them - never done, wastes power and you can
always use series-switching instead by putting the LED in series with the 220 ohm resistor between
supply and collector.
If you want to use 2 logic signals to control 4 LEDs I'd simply pick the logic chip that does this for you,
a 2 bit to 1-of-4 decoder (or a 3-input to 1-of-8 decoder, the 74HC138, a very common chip indeed).
There is a clever way to drive two LEDs from one pin which requires the LED's threshold voltages to be
more than 50% of the supply voltage (for instance green/blue/white LEDs typically). You connect
one LED (and its series resistor) between pin and ground, the other (and its resistor) between same pin
and 5V. Setting the pin to INPUT lights neither, to OUTPUT LOW lights one, OUTPUT HIGH lights the other,
you just can't have both lit (except by time-based multiplexing).
Jobi-Wan:
The transistors are BC547B PNP that came with the kit.
MarkT:
Your circuit only works with NPN, not PNP.
OldSteve:
BC547 transistors are actually NPN, not PNP.
Yes, those transistors are in fact NPN. I don't know how/where I misread that.
MarkT:
Pins D0 and D1 are connected to the USB serial chip ...
You are shunt-switching ...
I just labeled the connection points D0 and D1 in the diagram. They can be connected to any 2 output pins.
TIL 'shunt-switching'.. ..and that it should be avoided.
DVDdoug:
If you wanted to do it in hardware, you'd normally ...
MarkT:
simply pick the logic chip that does this ...
Yes, this is purely an exercise for me to learn to understand how transistors works. I was trying to build a '2 bit to 1-of-4 decoder' from scratch (with the few components I have). Thank you for the feedback.
Jobi-Wan:
Yes, this is purely an exercise for me to learn to understand how transistors works. I was trying to build a '2 bit to 1-of-4 decoder' from scratch (with the few components I have). Thank you for the feedback.
I should perhaps confess I was wrong about shunt-switching never being done, its rare, and usually
it would be used when using a constant current source powering a string of devices in series - you
short out any device you want to power down, diverting its current around it.
With relays this is easy, with transistors hard since the voltages float to whatever is necessary with
a current source (as opposed to the normal voltage source supply).
You could use shunt switching of a string of LEDs via opto-couplers in fact, but only for low power.
Another case where shunt-style circuit is used is for protection circuits that guard against overvoltage,
the idea being you short out the load causing the fuse to blow before the load is damaged.