I had a couple of goals for my circuit:
- Be able to drive 32 channels
- Use LEDs to indicate which lights are turned on
The heart of this circuit is the transistor (labeled 2N2222). A transistor, like a relay, uses a small amount of electricity to switch a larger amount of electricity. Current from the Arduino is used to switch on the current flowing through the transistor. The Arduino is connected to the transistor's base (labeled B) and allows current to flow from the collector (labeled C) the the emitter (labeled E).
I added a resistor (R2) to the circuit. The resistor reduces the current flowing from the Arduino. I selected R2 using Ohms Law. V=IR (Voltage = Current * Resistance). By definition, the diode drop from the transistor Base to Emitter is going to be approximately 0.7V. Since the Arduino will output 5V, I knew there would be 4.3V across R2. I picked a fairly large resistor, 4.7K, and used Ohms Law to see how much current would flow. V=IR can be rearranged to I=V/R. Substituting, I=4.3V/470K. I=0.9mA. That's perfect. The Arduino will have absolutely no problem, even if 32 separate pins are supplying 0.9mA each.
The 2N2222 has a current gain of about 100. That means that 0.9mA at the Base will allow 90mA to pass from the Collector to Emitter. Next, I needed to see if that would work for the top half of the circuit.
The top half of the circuit can't do anything when the transistor is turned off (no current can pass). When the transistor passes current, there will be 5V across the LED+R1, as well as 5V across the relay. Let's take the LED+R1 first. From the LED's specs, I knew there would be 2V across the LED at it's ideal 13.6mA. So, of the original 5V, 2V will dissipate across the LED, and 3V will dissipate across R1. Again, using Ohms Law, R=V/I. Substituting, R=3.0V/13.6mA. R=220. So, a 220 ohm resistor will limit the current and keep the LED happy.When connecting a relay, a diode needs to be wired backwards across the relay coil. This protects the transistor from the brief high voltage produced when the relay coil is switched off.
The relay needs 5V to activate it, so no resistor is needed there. From the data sheet, I expected approximately 60mA to pass through the relay. The 60mA through the relay, combined with the 13.6mA through the LED+resistor (plus zero mA through the diode) came to 73.6mA through the top part of the circuit. So, the transistor circuit should allow enough current through the top half.
An Arduino can briefly supply 40mA per pin. It certainly can't supply 73.6mA times 32 pins (that's over 2 Amps), so I need a power supply separate from the Arduino. I used a power supply from an old PC. It's not very difficult to do, and it's a fun project on its own.
I really enjoyed the next step. I needed to turn the schematic/breadboard circuit into the physical circuit. I found a circuit board at Radio Shack, and figured out how to scrunch the circuit into the minimum amount of space.
Then, I started soldering. The red LEDs are easy to see. Just below the LED is the 2N2222 transistor. Next to the transistor are the two tan resistors with the diode sandwiched in between. The relays are off in the high-voltage area of the project.
In my next blog entry I'll show how I hooked the driver circuits to the Arduino and to the relays.