3
\$\begingroup\$

I'm trying to create a circuit where a button press results in a microcontroller booting up and sending a wifi request. I'm relatively new to electronics, so likely have a big knowledge gap.

Similar questions have been asked before, eg:

But the answers there require mosfets, which I don't have on hand (I have BJT transistors, capacitors, resistors, diodes). I'm wondering if something simpler, like the following would work: schematic

Specifics

  • I'm using a ESP8266 (ESP01) microcontroller. This source suggests that GPIO3 is pulled high at boot
  • My intention is to have this be battery powered, so the power source is likely a battery source connected to a 3.3v mcp1700 LDO.
  • Because it's battery powered, there would ideally be no current draw when the device is powered off

The intended functionality is:

  1. I press the momentary switch S1, which grounds the MCU, causing it to power on in that moment
  2. Immediately at boot, GPIO3 is pulled high, which activates the BC337 transistor, which also causes the MCU to be grounded
  3. After a 200ms (or however long a button press lasts), I release the switch S1, but the MCU stays powered on due to the transistor
  4. I wait for the MCU to boot and send a request over wifi
  5. I have the MCU set GPIO3 to low, which causes the transistor to cut off grounding to the MCU and the MCU powers off

Note that I'm following the schematic shown on this page which uses a BC337 transistor as a switch to turn an LED on/off.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Not an answer but some observations: switching ground to a device such as a MCU should be avoided, switch the supply voltage instead; a mechanical switch is going to bounce, maybe your MCU won't have a big problem with it, maybe it will. \$\endgroup\$
    – vir
    Commented Oct 26, 2022 at 22:54
  • \$\begingroup\$ @JRE -thanks! I think I intended to say "BJT transistor" where I said "transistor". Will edit the post! \$\endgroup\$
    – maurera
    Commented Oct 26, 2022 at 22:58

2 Answers 2

1
\$\begingroup\$

This should work, but as mentioned in the comments, it is really better to switch the positive supply, which would require a PNP transistor (or PMOS device). The BC337 has a leakage of 100 nA maximum with base open, so that is not a problem, although it might be a good idea to put a resistor of maybe 50k from base to emitter.

Problems could arise if other devices connected to the processor have current paths to the power supply (battery) and ground, such that the device might be partially powered on through GPIO pins and protection diodes. You may need to make sure all external devices are connected to the MCU Vss circuit and not the battery, so the only current path is through the BJT switch.

If your MCU is powered by an MCP1700 LDO, you need to determine if you will be leaving it connected to the battery when powered down (which will be a 1.2 uA quiescent current drain), or switching the ground on it as well. In that case you would need to see if the higher battery voltage could cause any problems.

In any case, show the LDO as well as other external circuits to analyze the performance of the disconnect switch.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I don't think that a single BJT will work. The ESD protection will keep the GPIO pins near GND or VCC. If the MCU is Off, then GND and VCC are about the same. This state will cause base current to flow in any configuration that I can imagine. \$\endgroup\$
    – Mattman944
    Commented Oct 27, 2022 at 0:36
  • \$\begingroup\$ Thanks for this answer @PStechPaul. I also have BC327 transistors (which are PNP), so I'd be fine moving the transistor/switch to the positive side. There are no other devices connected apart from the battery/LDO (ie intended use is as a push button to control lights). \$\endgroup\$
    – maurera
    Commented Oct 27, 2022 at 0:55
  • \$\begingroup\$ @Mattman944 - I don't really understand your explanation. Ie - as soon as the GPIO is switched low, I expect the device to power off. How would ESD protection affect things? (Ie - I'm not following whether you're suggesting that there will be some current leakage or the device will stay powered on or something else?) \$\endgroup\$
    – maurera
    Commented Oct 27, 2022 at 1:00
  • \$\begingroup\$ Try it, it is a simple circuit. In my experience, powering down circuits is more complicated than expected. \$\endgroup\$
    – Mattman944
    Commented Oct 27, 2022 at 2:00
  • \$\begingroup\$ With a PNP on the high side, driven by an NPN on the low side, you can safely disconnect the higher battery voltage. Another option is an opto-isolator or solid state relay. \$\endgroup\$
    – PStechPaul
    Commented Oct 27, 2022 at 4:02
1
\$\begingroup\$

Here is the circuit close to what you are describing along with a good description as to how it works. It is labeled "Latching Power Switch Circuit (Auto Power Off Circuit) for ESP32, ESP8266, Arduino" by Rui Santos on the "randomnerdtutorials web site". This link will give you the schematic at fig 5. https://randomnerdtutorials.com/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino/#:~:text=The%20Latching%20Power%20Switch%20Circuit%2C%20also%20know%20as%20an%20Auto,down%20after%20executing%20a%20task. Let us know how it works out for you.

This does not switch the ground, which I recommend you do not do.

\$\endgroup\$
2
  • \$\begingroup\$ That shows the preferred method of using a PMOS device (and an NPN BJT) to implement a high side switch, but it does not address the OP's idea to switch the ground side of the MCU. \$\endgroup\$
    – PStechPaul
    Commented Oct 27, 2022 at 0:34
  • \$\begingroup\$ Thanks for the answer @Gil. I actually don't care about whether the switch is high side or low side (Ie - I have NPN and PNP resistors so could do either). I'm more just looking for an explanation of why/whether the extra components are needed in the linked website (and if so, if I could replace the MOSFET with a second BJT transistor) \$\endgroup\$
    – maurera
    Commented Oct 27, 2022 at 1:03

Your Answer

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

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