Electrical – Switching 12v pilot with 3.3v logic

esp8266logic-level

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.

Best Answer

  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:

schematic

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.