Electrical – Switch on an esp8266 with a npn transistor (2n2222A)

attinybatteriescesp8266transistors

this is my first question here, so I would like to ask you to kindly point out my mistakes regarding the question instead of just pressing the down arrow. That way I will have the opportunity to correct my mistakes on the next question and keep up the high question-answer quality of this forum. But now to my problem:

I'm currently working on a battery powered project using the Attiny85. Because I want to have the possibility to send push messages to my mobile phone I decided to add an Esp8266 D1 Mini to the circuit. To save power (I know that I could also put the Esp into deep sleep mode, but that would be boring and I wouldn't learn anything new ;)) I thought it would make sense to switch the Esp on and off immediately after sending a message using the transistor 2n2222A and the Attiny. But unfortunately the following circuit does not work:
enter image description here
enter image description here

The funny thing is that the circuit above works when I replace the Esp with a Led. Also reversing the polarity (i.e. instead of switching + with the transistor, – ) works with the Led without problems, but not with the esp.

Many thanks for your ideas in advance

Best Answer

There are generally three classes of issue here:

  • First, as pointed out, you've misapplied an NPN device as a high side switch (switching the power), and mixed up the terminals of the transistor, too. To switch the power rail, you need an actual high side switch, like a PNP transistor or better yet a PFET. Or, if you must use a NPN or N-channel device, then you need to create a power supply above that being switched, which is probably not worth the bother except when done internally in certain power switch chips.
  • You could try to switch the ground instead, but this quickly gets ugly when you have communication between the switched device and something else, like your ATtiny, especially if your ATtiny is running at 5 volts and the ESP at 3.3
  • In either case, most parts, and the ESP8266 in particular have a hard requirement that I/O signals may never be outside the range of the power rails by more than a diode drop. The practical meaning of this is that if you turn off the supply rail of the ESP8266, you must also take the serial lines sending to it low, and replace any pull-up of the receiving line with a pull-down.

Generally speaking there are two worthwhile paths you could pursue:

  • The first would be to drop the ATtiny and implement the entire project in the ESP8266; granted, this chip does not have as flexible low-power modes, and you'd probably need to find a regulator with a lower quiescent current than whatever is on your current board.
  • The second would be to get a proper high side switch for the power rail (either a PFET or a dedicate chip) and then wire up something like the classic NFET pass gate level translator to handle voltage translate between the ATtiny and the ESP8266, because that topology of level shifter can also properly handle having the lower voltage side powered down provided that you use the switched 3v3 supply for the shifter as well as the ESP8266. Even if your ATtiny is also running at 3v3 and not 5v, using this "level shifter" can solve the need to never drive a signal to a powered-down ESP; alternately you can carefully control the ATtiny GPIOs as the time you power down the ESP.

Another option to using a high-side switch is to find a 3v3 regulator to feed the ESP8266 which has an enable input, and drive that.