I'm working on a project that includes activating my garage door opener, very similar to the project on here using the Raspberry Pi.
What I'm wondering about though, is if I really need to use a relay? Would this work with a standard 2N2222 transistor? Since all I'm really trying to do is connect the circuit, would this work?
If so, how would I hook up? Just a single output pin to the transistor's base?
If it wouldn't work, why not?
Transistor or Relay?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Transistor or Relay?
Couple of questions about the garage door opener:
- How much current does it want?
- Does it need AC or DC current?
If you want to switch DC at less than 1A, the 2N2222 will work. If you want to switch DC at higher current levels, you'll need a more powerful transistor or a mosfet. If you need to control AC current, you'll need an SCR or a relay.
- How much current does it want?
- Does it need AC or DC current?
If you want to switch DC at less than 1A, the 2N2222 will work. If you want to switch DC at higher current levels, you'll need a more powerful transistor or a mosfet. If you need to control AC current, you'll need an SCR or a relay.
- PilotC150
- Posts: 132
- Joined: Sun May 04, 2014 9:39 pm
Re: Transistor or Relay?
It looks like it's 16VDC at 35mA. So a transistor should work.
So how would I wire up the transistor? I understand the basics of how it works, but I'm not sure how to actually wire it up on the breadboard.
Thanks for the help.
So how would I wire up the transistor? I understand the basics of how it works, but I'm not sure how to actually wire it up on the breadboard.
Thanks for the help.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Transistor or Relay?
First of all, take a look at the datasheeet and make sure you know which pin is which: http://www.adafruit.com/datasheets/PN2222A.pdf It's way too easy to connect a transistor backwards. It usually doesn't hurt anything, but the circuit won't do anything you expect.
In terms of connections, I'm going to assume the switch you're replacing has a pull-up resistor and the switch makes a connection to GND. Most switches are wired that way, and it's the easiest set of connections to explain. ;-)
A transistor provides a controllable current path between its collector and emitter, with the base providing the control signal. The 2n2222 is an NPN transistor, so the emitter wants to be closer to GND than the collector.
Based on those facts, the connections would be:
- Tie the emitter to GND.
- Tie the collector to the pull-up resistor.
- Tie the base to your RasPi GPIO pin through a 1k resistor.
The 1k resistor between the base and the RasPi is important.
A transistor is a 'transconductance amplifier', which is how engineers say, "the voltage at the input controls the current at the output." The input voltage is measured between the base and emitter, and is called 'V.be'. The output current flows through the collector and emitter, and is called 'I.ce'.
The relationship between V.be and I.ce is exponential: raising V.be by 60mV increases I.ce by a factor of 10, no matter what V.be and I.ce are when you start. As a rule of thumb, most BJTs are designed so I.ce is about 1mA when V.be is 0.65v. As a side note, the current that flows through the base (called 'I.b') is a somewhat constant fraction of I.ce.. 1% is a decent guess, but it isn't a value you want to rely on.
Since changing V.be by 180mV changes I.ce by a factor of 1000, almost all the interesting stuff happens near 0.65v. If you try to connect 3.3v to the base of a BJT, you'll basically short the pin to GND. A RasPi's GPIO pins are kind of fragile, so it's very possible that a direct connection to a BJT could damage the pin.
The 1k resistor between the RasPi and the 2n2222's base keeps things under control. It limits I.b to about 2-1/2mA, which is more than you strictly need but not a huge waste. If I.ce tries to increase, V.be and I.b will also want to increase. Increasing I.b would increase the voltage across the 1k resistor, which would push V.be lower, decreasing I.ce. The circuit will always float to a safe working level.
In terms of connections, I'm going to assume the switch you're replacing has a pull-up resistor and the switch makes a connection to GND. Most switches are wired that way, and it's the easiest set of connections to explain. ;-)
A transistor provides a controllable current path between its collector and emitter, with the base providing the control signal. The 2n2222 is an NPN transistor, so the emitter wants to be closer to GND than the collector.
Based on those facts, the connections would be:
- Tie the emitter to GND.
- Tie the collector to the pull-up resistor.
- Tie the base to your RasPi GPIO pin through a 1k resistor.
The 1k resistor between the base and the RasPi is important.
A transistor is a 'transconductance amplifier', which is how engineers say, "the voltage at the input controls the current at the output." The input voltage is measured between the base and emitter, and is called 'V.be'. The output current flows through the collector and emitter, and is called 'I.ce'.
The relationship between V.be and I.ce is exponential: raising V.be by 60mV increases I.ce by a factor of 10, no matter what V.be and I.ce are when you start. As a rule of thumb, most BJTs are designed so I.ce is about 1mA when V.be is 0.65v. As a side note, the current that flows through the base (called 'I.b') is a somewhat constant fraction of I.ce.. 1% is a decent guess, but it isn't a value you want to rely on.
Since changing V.be by 180mV changes I.ce by a factor of 1000, almost all the interesting stuff happens near 0.65v. If you try to connect 3.3v to the base of a BJT, you'll basically short the pin to GND. A RasPi's GPIO pins are kind of fragile, so it's very possible that a direct connection to a BJT could damage the pin.
The 1k resistor between the RasPi and the 2n2222's base keeps things under control. It limits I.b to about 2-1/2mA, which is more than you strictly need but not a huge waste. If I.ce tries to increase, V.be and I.b will also want to increase. Increasing I.b would increase the voltage across the 1k resistor, which would push V.be lower, decreasing I.ce. The circuit will always float to a safe working level.
Please be positive and constructive with your questions and comments.