0
\$\begingroup\$

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.

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

1 Answer 1

3
\$\begingroup\$
  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.

\$\endgroup\$
6
  • \$\begingroup\$ Should there be a pulldown on the transistor base? \$\endgroup\$
    – SRR
    Nov 3, 2019 at 16:29
  • \$\begingroup\$ @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. \$\endgroup\$
    – Big6
    Nov 3, 2019 at 16:40
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Big6
    Nov 3, 2019 at 17:11
  • 1
    \$\begingroup\$ @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 \$\endgroup\$
    – Big6
    Nov 3, 2019 at 17:15
  • 1
    \$\begingroup\$ @SimeonR see this (your very question): electronics.stackexchange.com/questions/56010/… \$\endgroup\$
    – Big6
    Nov 3, 2019 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.