0
\$\begingroup\$

So all i wanted to do was to control a 12V motor through a big spare transistor i had lying around. So i thought it may work and tested the transistor, and indeed it worked as a switch, when feeding a small voltage into the base, the switch activated with the power of 12V... Awesome!

So i thought heck let's skip the breadboard and actually create a real pcb circuit. So i powered all with 12V powersupply. Used a voltage divider with resistors to use same 12V powersupply to also power the ESP32 board(5V) itself. And then come the time where i placed the GPIO pin to the base of transistor to activate the switch... And just like that the board was FRIED. Foolish enough i grabbed another ESP32, tried again and you guessed it fried that one also XD.

So what went wrong here? How did the 12V external power supply manage to get inside the board and wreak havoc? Do i maybe need some diodes or something else that i am missing here :/

enter image description here

Thanks before hand if you can be of any help to make my brain understand a little bit more about electronics :D

-Update! Burned a third ESP32(this time i was clumpsy, accidently fell over the powersupply and shorted it XD)... But my transistor was a PNP transistor and the powersupply in the sketch i drew was drawn in opposite direction!

\$\endgroup\$
10
  • 5
    \$\begingroup\$ First of all, you can't power anything via the resistor divider. Even a short circuit on your 5V "output" would only get 120 microamps. Are you sure the boards are really fried, or just not getting power due to resistor divider? Secondly, you have no base resistor between GPIO pin and transistor base. That might also fry something. Third, there is no protection diode at the transistor from protecting it from the inductive load when it turns off. \$\endgroup\$
    – Justme
    Sep 24 '20 at 19:34
  • 2
    \$\begingroup\$ There are so many things wrong here it's hard to know where to start. For starters: Why can't you use a resistor divider as a voltage regulator, Why is a base resistor important. You have now seen that building random circuitry without knowing the basics makes electronics an expensive hobby ;-) \$\endgroup\$
    – StarCat
    Sep 24 '20 at 19:41
  • \$\begingroup\$ You need a catch diode across your motor, you need a base resistor for your transistor. And you should check if gpio2 might need to be high at boot (not saying it does, but the ESP series have boot mode strapping on some pin which people often break this way... I'll leave looking up which pin to you) \$\endgroup\$ Sep 24 '20 at 19:45
  • \$\begingroup\$ @StarCat Oh, Very good link about the resistor divider issue! Thanks for that. Now what i left to wonder is why it fried the board? Even though i would have a resistor at the base of transistor(which i will have next time :D), i somehow doubt it would still not get killed. I quickly checked with my multimeter the voltage from the base(without base being plugged in) to the emitter, and there was 12V across it. Could this mean that when i plugged my GPIO to the base it got feed a whooping 12V in it somehow? \$\endgroup\$
    – CoffeDev
    Sep 24 '20 at 19:52
  • 1
    \$\begingroup\$ @CoffeDev If the placed the GPIO pin to the base of transistor to activate the switch step had even a tiny bit of contact bounce (it did), the inductance of the 12 V motor could have created a 24 V reverse voltage spike. Please see Why add a diode to a transistor controlled DC motor circuit? \$\endgroup\$ Sep 26 '20 at 14:01
2
\$\begingroup\$

Summary: One likely cause of damage to the ESP32 is the use of a PNP BJT on its own, to drive a load at a voltage higher than the GPIO voltage. (There are further problems with the schematic which could cause other damage too, but I'm focusing mainly on the use of a PNP BJT.)

Details:

How did the 12V external power supply manage to get inside the board and wreak havoc? Do i maybe need some diodes or something else that i am missing here :/

There were / are several problems with the schematic:

  • Using a resistor divider to produce a lower voltage power supply (also mentioned by Justme and by StarCat)
  • Missing base resistor (also mentioned by Chris Stratton)
  • Missing flyback diode across the inductive load (also mentioned by Andrew Morton and Chris Stratton)

The latter two points in the above list could cause damage to the transistor.

However, your later comment is very important, and this is what I want to focus on:

I quickly checked with my multimeter the voltage from the base(without base being plugged in) to the emitter, and there was 12V across it. Could this mean that when i plugged my GPIO to the base it got feed a whooping 12V in it somehow?

Yes, that's exactly what it means. It is also the behaviour expected if you have a PNP BJT as a high-side switch, instead of the NPN BJT as a low-side switch shown in your schematic. And now your recent edit has confirmed that the schematic is wrong, and you were indeed actually using a PNP BJT:

[...] my transistor was a PNP transistor and the powersupply in the sketch i drew was drawn in opposite direction!

So that makes part of your problem a repeat of this question: "PNP high-side transistor switching with microcontroller". The answer to that question from user Transistor explains the consequences of trying to use just a PNP BJT to directly control a higher-voltage device, from an MCU GPIO (please go and read that answer).

This image is copied from that linked answer by user Transistor:

schematic

simulate this circuit – Schematic created using CircuitLab

Your schematic showed you were using circuit (a) above (NPN BJT low-side driver), but in fact you were using circuit (b) above (PNP BJT high-side driver, with a higher load voltage than the GPIO voltage).

The orange line on circuit (b) shows a current path, due to the forward-biased emitter-base junction of the PNP BJT, which can damage the MCU directly and potentially (through the ESD "diodes" in the MCU) also raise the supply voltage to the MCU too (causing further damage).

User Transistor has another useful explanation of this issue (and other useful information) on their own website here: GPIO high-side driver fail.

You said in your update:

i now use an actual npn transistor c945, that works wonder!

NPN transistors labeled C945 (2SC945) are made by several manufacturers, and their specifications can vary slightly (example datasheet). However it would generally be called a small-signal transistor. Make sure that its ratings are suitable for your 12 V motor - and add a base resistor and a flyback diode.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Absolutely fantastic explanation of my very poorly designed schematic! I did upgrade it to another small transistor i had lying around that supported 700mA just in case. Big thanks for the detail rich explanations! \$\endgroup\$
    – CoffeDev
    Sep 26 '20 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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