# Switching 12v pilot with 3.3v logic

I have an entry gate pilot operating on 12v. I would like to connect it to my esp8266 (3.3v) to control it over the WiFi. I would like to use 12v power line which I already have. The components which I have at home are couple of 2N2222 transistors and some relay modules (5v).

I have a two problems here: 1. How to power esp chip? Buy some 12v to 3.3v step down converter or I could use 2N2222 somehow? 2. How to switch 12v using 3.3v logic? I know that I could use a relay, but they are operating on 5v logic and I would like to avoid 3 different voltage levels in this circuit.

Of course I could buy some extra components but using what I already have would be nice.

• have you tried to see if your relays will switch with 3.3 v? Nov 2, 2019 at 22:13
• Good question. I have one of those - aliexpress.com/item/32340902998.html I'll check that when I'll get home. Nov 2, 2019 at 22:22

1. How to power esp chip? Buy some 12v to 3.3v step down converter or I could use 2N2222 somehow?

You need to get a dedicated regulator. You can either get a linear regulator or a buck converter. The simplest approach is to use a linear regulator, you can find them really easy to meet your specs and are cheap.

1. How to switch 12v using 3.3v logic? I know that I could use a relay, but they are operating on 5v logic and I would like to avoid 3 different voltage levels in this circuit.

You could use your 2N2222 as a switch. This is a BJT transistor, so you need to add an appropriate base resistor. It is well documented how to use a BJT as a switch, but in general, it looks like this:

simulate this circuit – Schematic created using CircuitLab

Now, you need to make sure your load current is within the specs of your 2N2222 (I think this is <700mA). See this question if you want to know how to determine the appropriate base resistor value.

Another approach to switch 12V using 3V3 logic, is to use a MOSFET. You have to look for a "logic level" MOSFET—these have turn-on voltages down to even 2.5V, so you could easily find the one you need. Unlike a BJT (e.g 2N2222), you don't worry too much about the gate resistor (what we've called base resistor before), but you do care about having enough voltage to turn it on. You can find a lot more if you look for BJT and MOSFET as switches.

• Should there be a pulldown on the transistor base?
– SRR
Nov 3, 2019 at 16:29
• @SimeonR For a MOSFET, it's probably a good idea since its gate can remain charged if you don't actively drive control signal low. For a BJT, the base resistor, in series, as shown, is what you'd need.
– Big6
Nov 3, 2019 at 16:40
• @SimeonR In summary, the MOSFETs gate behaves kind of as a capacitor. Not that the BJT does not have input capacitance but it is much less of an issue. When you apply voltage to the gate, you charge up that capacitance and in the absence of a pulldown, for example, it can remain charged up indefinitely. In a BJT, the capacitance at the input or base in this case, doesn't pose much of a challenge because even though it's present, its charge can leak through the base-emitter junction (remember that's modeled as a diode), so there's a path to GND to discharge the input capacitance.
– Big6
Nov 3, 2019 at 17:11
• @SimeonR this is a very broad topic though but you can find tons of resources online about it. But it actually would not hurt to add a pulldown to the base of a BJT, some big value like 47k could make it the design more robust, chances are though, that you'd be fine without it
– Big6
Nov 3, 2019 at 17:15
• @SimeonR see this (your very question): electronics.stackexchange.com/questions/56010/…
– Big6
Nov 3, 2019 at 17:18