I have ESP32 and I'm using it to read/write data from an SD card that is directly connected over SPI. This works fine. Now I want to switch on the ESP32 automatically by switching on the 3.3v power supply when an SD card is connected. When the SD card is beeing disconnnected, the power should be switched off.

I've tried to accomplish this using a 2N2222 transistor but I'm stuck now. My plan was place the ESP32 on the collector and GND on the emmiter. I wanted the base to be switched by a connection from the GND pin of the SD card (using a 220ohm resistor between SD card GND pin the power supplies GND to get part of the current to the base). This leads to the transistor switching just fine, but with this setup the SPI doesn't work anymore.

What can I do to make this work. Is there another way to switch on/off power when an SD card is connected?

Sorry for the bad schematics, its my first try.


simulate this circuit – Schematic created using CircuitLab

  • 2
    \$\begingroup\$ Welcome to EE.SE. A schematic is better than words. You can add one in using the CircuitLab button on the editor toolbar. Double-click a component to edit its properties. 'R' = rotate, 'H' = horizontal flip. 'V' = vertical flip. Note that when you use the CircuitLab button on the editor toolbar and "Save and Insert" on the editor an editable schematic is saved in your post. That makes it easy for us to copy and edit in our answers. You don't need a CircuitLab account, no screengrabs, no image uploads, no background grid. \$\endgroup\$
    – Transistor
    May 23, 2020 at 8:03
  • \$\begingroup\$ Please draw a schematic of what you have done. Based on your description, I can only tell it's not correct. \$\endgroup\$
    – Justme
    May 23, 2020 at 8:47
  • 1
    \$\begingroup\$ Thank you for your replies. I have added a schematic now. \$\endgroup\$
    – Davemaier
    May 23, 2020 at 22:30

1 Answer 1


Logic circuits rely on good ground connections to function properly and putting anything in the way is going to lead to problems. Sensing current on the supply pins has a better chance of working, as they're generally more tolerant of a wider range of voltage.

But there's a far better way to achieve what you want to do - use an SD socket with a built in switch to detect card insertion, like this one:

enter image description here

Most SD card sockets have a similar facility, it shouldn't be hard to find one.

  • \$\begingroup\$ Hi Finbarr, thanks for your answer! It's very good for me to know that even the manufacturers of sd card sockets use another seperate switch. Since my project will only use an SD card as a storage solution that is connected via a self built connector that uses pogo pins when it is done, I would appreciate to have only a minimum of necessary pins (e.g. the six pins of the SPI connection). Of course I could add a seperate mechanic switch somewhere that indicates that the storage chip is connected, but I would love to have an option to go without the switch. \$\endgroup\$
    – Davemaier
    May 23, 2020 at 21:35

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.