Use transistors to switch between two signals - Page 1
Forum section: electronics / beginners

author: gbuilder
author_rank: Newbie
timestamp: April 19, 2018, 10:09:22 am
content: Hello,As a beginner, I have tended to use lots of relays for logic and switching, since the way they operate is very intuitive.I'm staring to understand that in many cases, using transistors for switching is a better choice (cheaper, smaller, better for high frequency switching, etc)I've enjoyed learning how to use transistors to switch a signal on or off, invert, buffer and provide gain. Very useful.I'd now like to understand if it is possible to use transistor circuit to switch between two different signals.Specifically, I'd like to find a circuit which will perform the same function as my relay switching circuit below.In this case, the MCU digital output state determines which signal from the inputs is connected to the output.Update: Thanks hamster_nz for spotting the flaws in my relay circuit. It was just a quick sketch to illustrate my question, but you are quite correct and I have uploaded a corrected version which might be useful for people reading the thread in future:

author: gbuilder
author_rank: Newbie
timestamp: April 19, 2018, 10:57:51 am
content: Hmm, or should I be using an "analogue switch"/"multiplexer" IC for this function?

author: Zero999
author_rank: Super Contributor
timestamp: April 19, 2018, 11:00:23 am
content: Quote from: gbuilder on April 19, 2018, 10:57:51 amOr some logic gates, if there are only two signals.

author: ogden
author_rank: Super Contributor
timestamp: April 19, 2018, 11:08:06 am
content: Quote from: gbuilder on April 19, 2018, 10:09:22 amIndeed it is possible. After all digital chips are made out of transistorsI suggest you to skip transistor switch build, just learn multiplexers. Better invest your time into something more usefulhttps://en.wikipedia.org/wiki/MultiplexerWhat you want is 2:1 SPDT switch (multiplexer), likehttp://www.ti.com/product/cd4053bthat chip have 3 switches inside.

author: boffin
author_rank: Unknown
timestamp: April 19, 2018, 11:29:48 am
content: Quote from: ogden on April 19, 2018, 11:08:06 amActually the 4053 is a single 1P8T switch (pick one of, fed from a 3-bit numberWhere as the 4066 might be more useful (and easier to find). Four individual SPDT switcheshttp://www.ti.com/product/CD4066B

author: Zero999
author_rank: Super Contributor
timestamp: April 19, 2018, 12:13:17 pm
content: Quote from: boffin on April 19, 2018, 11:29:48 amNo, '4053 is three SPDT switches.https://assets.nexperia.com/documents/data-sheet/HEF4053B.pdfIf this is running off 5V, then the 74HC4053 should be used, as it has a lower on resistance. If only one switch is required, then all three can be connected in parallel, for a third of the resistance.https://assets.nexperia.com/documents/data-sheet/74HC_HCT4053.pdfIf it's just one channel, then a quad NAND can be used. It will be slightly slower, than an analogue switch, but it has the advantage of being buffered.

author: ogden
author_rank: Super Contributor
timestamp: April 19, 2018, 01:36:30 pm
content: Quote from: boffin on April 19, 2018, 11:29:48 amNo. Three individual SPDT switches.QuoteNo. 4066 is quad bilateral switch

author: gbuilder
author_rank: Newbie
timestamp: April 19, 2018, 09:12:44 pm
content: Your comments have been very insightful, thank-you.----->Picks up Horowitz & Hill to read about digital logic and multiplexers

author: gbuilder
author_rank: Newbie
timestamp: April 19, 2018, 09:38:11 pm
content: Quote from: Hero999 on April 19, 2018, 12:13:17 pmWould you mind talking me through the operation of the circuit you showed here? It looks to me like the decision of which input is connected to the output will depend on the state (high/low) of the input signals.In my relay circuit, the selection of which input signal is connected to the output is completely determined by the control pin.Forgive my slow comprehension, this is why I'm always tempted to use relays - their operation is so simple!

author: ogden
author_rank: Super Contributor
timestamp: April 19, 2018, 09:54:07 pm
content: Quote from: Hero999 on April 19, 2018, 12:13:17 pmOne more disadvantage comparing to analog muxes - it's unidirectional.

author: Jwillis
author_rank: Super Contributor
timestamp: April 19, 2018, 11:42:29 pm
content: Why couldn't he use a simply inverter circuit? The two out puts could be used to switch two more transistors to pass the two inputs to one depending on whether the input to inverter is high on low.

author: tron9000
author_rank: Frequent Contributor
timestamp: April 20, 2018, 08:35:45 am
content: Quote from: gbuilder on April 19, 2018, 09:38:11 pmFirst off, truth table for NAND Gate:0 0 = 10 1 = 11 0 = 11 1 = 0the switch dictates which signal will be passed to the output.When the switch is closed, the signal to the gate connected to 2 goes high, Any state change on pin 2 will be passed to that gates output. With the switch still closed, the gate with both pins tied together inverts the signal from the switch, thus there is a low signal to gate for pin1 and any state change on pin 1 will be blanked (output will always be 1).so at the final output gate, one input is high (from gate 1) and the other input is changing state and so the output changes state according what is present at 2.open the switch and everything swaps, the output now changes state WRT pin 1.The reason Hero999 has show using NAND gates are that NAND gates are/were easier to obtain and produce, Cheaper than AND counterpart, and come in Quad DIP packages:74LS00though it'd be easier to explain this with AND gates. Hey, life gives you lemons...

author: boffin
author_rank: Unknown
timestamp: April 20, 2018, 05:18:23 pm
content: Quote from: Hero999 on April 19, 2018, 12:13:17 pm

author: hamster_nz
author_rank: Super Contributor
timestamp: April 20, 2018, 08:11:10 pm
content: Quote from: gbuilder on April 19, 2018, 10:09:22 amI don't think that that circuit actually will work as you expect. It seems impossible to turn the relay on. A wire from IN1 to OUT is all you need to perform the same function.Typical internet - even when you supply a circuit schematic, nobody looks at it!But being serious now, you might have been meaning this circuit, as rendered in DaveCAD on scrap paper (please ignore that in and out are transposed):

author: gbuilder
author_rank: Newbie
timestamp: April 20, 2018, 10:07:43 pm
content: tron9000 thank-you for the clear explanation. My confusion was that I was thinking of the signals as analogue. CLearly this is a solution suitable for digital logic signals.hamster_nz yes sorry, I must admit I haven't checked the circuit in SPICE or on the breadboard. Another rookie mistake. With NPN transistor switch, for predictable behaviour the load should be between the positive supply and the collector, not between the emitter and ground.

author: Zero999
author_rank: Super Contributor
timestamp: April 21, 2018, 12:35:09 pm
content: I'm amazed most people, including myself, missed that. Yes, it won't work. R2 will limit the current too much for the relay to turn on.It might still work with an emitter follower, just with R2 and R1 removed. The relay will get about 4.4V, which may still be high enough to activate it.

author: ogden
author_rank: Super Contributor
timestamp: April 21, 2018, 07:21:23 pm
content: Quote from: Hero999 on April 21, 2018, 12:35:09 pmThat's because question was notaboutparticular circuit. - I missed (to be honest - ignored) to look into that circuit as well

author: glarsson
author_rank: Frequent Contributor
timestamp: April 21, 2018, 08:37:02 pm
content: Quote from: Hero999 on April 21, 2018, 12:35:09 pmDidn't miss it. The circuit is weird, but it will work with a sensitive 2V relay. However, it wasn't relevant to the question.

author: boffin
author_rank: Unknown
timestamp: April 22, 2018, 12:54:30 am
content: Just take HamsterNZ's circuit, replace the transistor with a FET (2N7000), remove the resistors and you're in business (you could keep the Rs if you really wanted, but if the source is guaranteed Hi/Lo you're fine). Almost no voltage drop across the FET, the relay will turn on/off just fine, rather than being a bit iffy at 4.4V

author: tron9000
author_rank: Frequent Contributor
timestamp: April 23, 2018, 08:40:29 am
content: Quote from: gbuilder on April 20, 2018, 10:07:43 pmAhh, well then, your best bet is an analogue mulitplexer:DG409glad you thought my explanation was "clear" - usually I'm not very good at explaining things!

author: hirada
author_rank: Regular Contributor
timestamp: April 24, 2018, 11:58:43 am
content: A reply from a beginner: My (simplified) version of yours to turn on the relay would look like this. The need of a base resistor could propbably be argued and you only have ~4.3V for the relay as opposed to 5V.Edit: Assuming of course, the MCU output delivers enough current and is 5V as well, so you have 5Vb.

author: tron9000
author_rank: Frequent Contributor
timestamp: April 24, 2018, 02:22:33 pm
content: Quote from: hirada on April 24, 2018, 11:58:43 amThe beauty about relays is that even if you switch it low side, leaving one end "flapping in the breeze" its not going to float and/or accidentally turn on.

author: Lt_Flash
author_rank: Regular Contributor
timestamp: April 25, 2018, 07:23:32 am
content: You can use LTC4412 to switch between two power sources and also can control it from MCUhttp://www.analog.com/media/en/technical-documentation/data-sheets/4412fb.pdfIf that's not a power signals - then why just not use a multiplexer? There's a lot of 2-channel ones available.

author: gbuilder
author_rank: Newbie
timestamp: April 25, 2018, 10:36:54 am
content: Thank-you all for the input, some very interesting comments and I have learned a lot!I've enjoyed following the different approaches to solve this very simple problem, I guess that's what makes electronics design interesting.Sorry for the error in my initial schematic, I've uploaded a correction to the OP.I've decided to order a bunch of 4053 multiplexer ICs. Of all the 405x series, this seems particularly versatile and might come in handy in many other situations. Also I could get 10 for £2

author: IanMacdonald
author_rank: Frequent Contributor
timestamp: April 25, 2018, 12:44:51 pm
content: A CD4016 is similar to the 4053 but gives you four single switches. Another arrangement that works well where small signal handling with low noise and distortion is needed, is a pair of JFETs such as 2N3819's.

author: ogden
author_rank: Super Contributor
timestamp: April 26, 2018, 08:38:50 pm
content: Quote from: IanMacdonald on April 25, 2018, 12:44:51 pmCD4016 have four bilateral (on/off) switches. OP asked for "switch between two signals", 2:1 SPDT.

author: glarsson
author_rank: Frequent Contributor
timestamp: April 26, 2018, 08:55:13 pm
content: Quote from: ogden on April 26, 2018, 08:38:50 pmYou can build a SPDT switch from two 4016 switches if the control signal is also available in inverted form. The remaining switches in the 4016 can be used as an inverter.

author: tron9000
author_rank: Frequent Contributor
timestamp: April 27, 2018, 08:06:42 am
content: Quote from: glarsson on April 26, 2018, 08:55:13 pmlike this?

author: glarsson
author_rank: Frequent Contributor
timestamp: April 27, 2018, 08:25:10 am
content: Yes. These switches can be used as general purpose logic elements. They can be connected in series and parallel to get AND and OR functions.