Transistor switch without polarity

I've successfully used an Arduino Uno to trigger Halloween props by closing the normally open circuit on an SRD-05VDC-SL-C relay. I am basically replacing a contact switch and tapping into each prop's "try me" circuit as depicted in the following 2.5 minute video:

Link to instructional video

I'm now trying to replicate the functionality on a breadboard by connecting the base leg of a BC337 transistor to a digital output pin on an ATMEGA328P-PU. I can make it work with every prop but as is suggested in the video I have to respect polarity when using the transistor. The relay works with every prop irrespective of polarity. Is there a way for me to make the transistor work irrespective of polarity too?

• Welcome to EE.SE. In a word - NO. Bjt transistors are fussy about polarity, voltage and current. Why not stick to the instructions and just be happy that it works. – user105652 Aug 13 '18 at 22:36
• Thanks Sparky! I create multiple haunt "zones" each year and have hundreds of props to choose from so having to customize each circuit is a deal breaker. I'm trying to design a custom PCB and hoped to take cost out of the assembly by replacing relays with transistors but if relays forgive polarity and transistors don't then that forces me toward relays, which also means that I'm probably better off just buying Arduino clones and relay boards and designing my own shield to connect them. – Keith Burk Aug 13 '18 at 22:49
• Try using two back-to-back MOSFETs. (Two back-to-back, so that the body diodes are in opposite directions) – user253751 Aug 14 '18 at 1:43
• How much voltage does the switch need to handle? Are the props battery operated or are they connected to a shared DC supply? – Jasen Aug 14 '18 at 2:18
• Each prop is powered separately by either 4.5 volts through 3 AA or AAA batteries or a 6V DC power adapter. The largest current draw is a few hundred milliamps. – Keith Burk Aug 14 '18 at 9:38

1) Put an optocoupler inside each treat when you modify it.

The H11AA1 AC isolator costs 25c and is AC input i.e. the led input side is unpolarised. If you fit one of these inside each treat across the switch (you still need to get polarity right when you fit it) then the wiring polarity to the opto is irrelevant. Cheap, one part, low on voltage.

You could just use a simple opto in the treat with a polarised plug, so that led polarity is correct.

You could also connect a single opto across two pins of your mcu (A,B), and drive it A hi, B lo, then B hi A lo. Thus it gets triggered no matter which way you wired the led up.

1b) If you want the switch side to be unpolarised, then use two simple optos (Opto1,2 below) (these seem to be 3c from CN) with the leds in series, and the transistors swapped. In this case put the optos on the MCU board.

BTW if you are triggering one treat at a time, then an 8 bit port is able to control up to 56 optos (1b) directly.

2) use an optofet isolator. Not really cheaper than relays, but lower on current, full isolation and no polarity or on-voltage issues.

I personally would go for optos or relays especially if any of the treats are not battery powered.

Bu if you really want to have problems...

a) Since you have to modify each treat anyway, just put a standard 2 pin polarised connector on when you modify them e.g 3.5mm jack, and then they will be correctly polarised when you plug them in. Drive with a transistor.

4) Here's a non polarised switch. You can also use it with optos for Q1 to get a non polarised output. The draw back is the on voltage is 1.4V using ordinary diode bridge, or 0.8V with schottky bridge.

simulate this circuit – Schematic created using CircuitLab

• Thanks Henry! My understanding of electrical components is limited so I'll have to do some research to learn how to execute your recommendations. A quick search on Digikey makes it seem as if H11AA1 costs about as much per piece as the relays that I'm trying to replace. Is there a bigger cost difference if ordered directly from China? In the second half of your post you say "if I really want to have problems". Is that sarcasm or a typo? – Keith Burk Aug 14 '18 at 9:48
• If you are hooking things with power adaptors together, then there are small current and quite high voltages between them. It makes connecting transistors to ill defined circuits an unreliable proposition. Having clean isolation (optos) avoids that. I was surprised on aliexpress that plain 4 pin optos are 3c each. Probably not the best, but I doubt you care. Using a pair of them is only 6c, and actually not to hard to just wire directly to if you are good at soldering. – Henry Crun Aug 14 '18 at 11:18
• I would probably start with a simple opto, and put the optos inside the props - running long wires from the random circuitry is going to cause more problems than running 5V to the opto leds. It should be no problem to workout the switch polarity when you modify the prop: one way it works, the other it doesn't. – Henry Crun Aug 14 '18 at 11:22
• Thank you team optocoupler! I had a 4N35 optocoupler hanging around from an Arduino starter kit that I bought a few years ago but never had the opportunity to experiment with. I connected pin 1 to VCC through a 1k ohm resistor, pin 2 to an ATMEGA328P-PU digital output pin, and my prop's VCC and GND to pins 4 and 5. All 5 of the props that I checked both ways (reversing pins 4 & 5) triggered irrespective of polarity. I still have some research to do to understand why it works but I greatly appreciate all of your insight to point me in the right direction! – Keith Burk Aug 15 '18 at 2:13
• If you look at an npn transistor, there are two diodes "pointing" from the base. One is B->E. The other is B->C. Both of them can work to turn on the transistor. Except the proper B->E base is 10x more gain. When you swap C and E gain is very low. You can test this by seeing how much current flows through it from 5V with a meter, then swap C&E. This is working because (most) of your props are only needing a very tiny switch current to turn on, so it doesn't matter. (I didn't suggest this because it is dodgy - even for me) – Henry Crun Aug 15 '18 at 2:29

A quick search at Digikey shows several FET-output opto-isolator devices that are relatively low-cost and in stock. These have dual FET output stage, which makes the load polarity not relevant. In other words, they will handle either polarity of DC and will work with AC as well.

I sorted the available parts by cost and came up with the following two part numbers: TLP222G, TLP222G-2

The "-2" variant is two identical parts in a single package.

Digikey part number TLP222GF-ND costs Can $1.45 in quantity 10, dropping down to Can$1.29 in quantity 25. The dual versions cost almost exactly double, so no real savings in cost.

This is a 4-pin through-hole device. Max 350V, Max 120 mA, Max on-resistance 50 Ohms. The LED has a forward voltage less than 1.6 Vdc and the datasheet says the device is fully enhanced with 3mA LED current.

This is a very easy way to accomplish full isolation at low cost. You can put a whole bunch of these along with the LED resistors on a strip of Veroboard (stripboard).

You will need two transistors (one PNP, one NPN) to duplicate the polarity-independent switching functionality of your relay.

Your relay operates irrespective of polarity because it is a switch operated by electromagnetism. The relay does not care about the polarity (direction of current flow). When current is flowing, electromagnetism closes the contacts.

Your BC337 (NPN) transistor operates when you 'bias' the junction, by placing a positive voltage on the base. Add a BC327 (PNP) transistor, this will operate when you place a negative bias on the base.

Bottom line, you need two transistors to take the place of a relay when you cannot control the polarity of your input.

Since you can buy a dozen transistors for the price of a relay, you're still way ahead of the game.

• Thanks KD Mann! This sounds like it could be an elegant solution to my problem but I'm still not sure how to set up the circuit. When a PIR sensor input is HIGH I want to send 5V to the transistor base, closing the circuit, and when the PIR sensor is LOW I want to send 0V to the base, opening the circuit. If I use one NPN and one PNP isn't that like an OR gate that will always be open? – Keith Burk Aug 13 '18 at 23:46
• Could you please explain how using a PNP and an NPN will give "polarity-independent switching functionality of your relay". – Andy aka Aug 14 '18 at 11:57