Introduction
The next step in the
MMS Photo-inator project is to design a circuit to switch the light bulbs in the buttons on an off using transistors. The
Raspberry Pi 2 can't provide enough power to make the lights bright enough but it can control electronic switches that allow a higher powered power source to turn the lights on.
Using transistors turned out to be very difficult to me. The concept of a transistor is pretty simple but actually getting a circuit working is not. I burned out several transistors trying different things. I have also read various sources to learn more about transistors but it does not seem to help. Last weekend,
Royce from the
Milwaukee Makerspace helped me build a circuit that worked. I'll try to document what I learned for my own edification.
Learn About Transistors (good luck)
Here are some links to learn more about how to use NPN transistors as a switch:
Transistorized Switching Circuit
The objective is to turn three individual light bulbs on and off from my
Raspberry Pi using transistors. The basic circuit is shown below. Note that everything, 12v PSU, RPi, and lights share the same ground. This is important.
Transistors will be used as electronic switches to allow current from the 12v, 1.8A power supply to flow through the light bulbs. The Pi will send a 3.3v signal to the base pin on the transistor. This is the signal that tells the transistor to turn on the light bulb.
According to
this site, the Raspberry Pi can safely put out a maximum of 16 mA per GPIO pin and a total of 50 mA on all GPIO pins. So, I have to be careful and limit the current from the Raspberry Pi to the base of the transistor to 16mA per transistor.
Transistor Specifications
The first thing to do was to determine the characteristics of the transistor my project needed.
This site was helpful to determine what transistor to use.
The transistor has to handle the output from the power supply I will use -- 12v and 1.8A (max) -- to power the lights. Even though the lights only draw 0.25A, the PSU can put out 1.8A. I think it is possible for the transistor to draw the full current in some circumstances so I need a transistor that can handle the maximum current from the PSU. The parameter for current is called Ic(max) on the datasheets. The parameter for voltage is called V
CEO (max). When I look at the datasheet for a transistor, it has to have characteristics that fall within these two specifications.
Finally, the amount of current that the base needs must be <= 16mA. This parameter is called I
B. To determine the I
B parameter, you have to find the formula on the datasheet. It is usually something like I
C = X * I
B. Basically, divide the current for the load by X to find the current to send to the base. In my case, the load current is 1.8A maximum. If, for example, a particular transistor has a formula of I
C = 100I
B, I
B would be equal to 1.8A / 100 or 18mA.
Finding a Transistor
Next, I had to find a transistor that meets the specifications. The
Milwaukee Makerspace has several NPN transistors in bulk. I looked up the specifications for each one on the
http://www.datasheets360.com/ website. Unfortunately, none of the NPN transistors on-hand matched the requirements. It seemed like I was going to have to buy a
MOSFET transistor like
this one on
SparkFun. On a hunch, I looked through the
hack rack at the 'space for any parts that may have transistors and found a circuit board that had sixteen
2N6045 NPN transistors. According to the
datasheet, these transistors have an I
C (max) of 10A, and a V
CEO (max) of 100V. Both of these are sufficient for this project. The I
B formula for this transistor is I
C/100 or 18mA in my case. This is just a bit higher than the Pi would like but, the load should not draw that many amperes. The nominal current that the lights will draw is 0.25A. This means that the base current needs to be 2.5mA under
normal load--well within the Pi's capacity. Finding the circuit board was an unexpected blessing. Thanks, Big Guy.
I was able to remove a couple of transistors from the circuit board using a soldering iron.
Resistor for the Base
Its important to prevent the transistor from pulling too much current from the Pi and damaging it. The Pi can be protected from this by placing a resistor between the Pi and the base pin. Determining the size resistor that is needed was a bit complicated.
First, we made a circuit with one resistor and one 12v lamp. A
regulated power supply was used to determine the minimum current that would turn on the 2N6045 transistor. To find the exact current level that the circuit was pulling, I unplugged the positive cable from the PSU, connected the red cable from the
multimeter to the positive out on the PSU, then, connected the black lead on the multimeter to the circuit. The minimum current required to activate the transistor turned out to be 8mA. Finally, using a multimeter to measure the volts from the base to the emitter while the light bulb was on, showed that the PSU was supplying about 1.4v at this current level.
This means that the voltage from the pin on the Pi needs to be lowered from 3.3v to 1.4v at 10mA (rounded up from 8 just to be safe). The resistor has to remove 3.3-1.4 or 1.9 volts. Using
Ohm's law to calculate the resistance works like this:
R = V/I or
R = 1.9/0.01A or
R = 190 ohms.
Putting a 190 ohm resistor between the Pi GPIO pins and the base pins of the transistors should keep the Pi safe from pushing out too much current, while providing enough volts to activate the transistor.
I put a 180 ohm resistor (the 'space had a 180 or 220 ohm but no 190) in the circuit and connected the Pi's 3.3v output pin to the base. The light turned on!
That was a lot of work and very frustrating at times. I would have never made it this far without
Royce. That is what is so great about the
Milwaukee Makerspace. There is usually someone around who can help you through the rough spots.
Next, I need to remove some more resistors from the board and build a prototype of the complete MMS Photo-inator project.