After frying a Rpi with this montage 6 months ago:

enter image description here

I followed advice from kind users here and modified the wiring to this back in February:

enter image description here

It has been working fine for 6 months and suddenly yesterday, this montage fried a Rpi again, probably due to a short circuit or maybe PWM failure pushing back current in GPIO.

Now looking for advice on how to protect GPIO on the Rpi. Diode or any other economic solution... PLEASE BE EXPLICIT AND VISUAL IN YOUR ANSWER as I'm a visual learner. If it requires rewiring please draw it or a particular component added, then please name it.

PWM module I'm using:

enter image description here

The Rpi is powered/grounded via a 12V to USB (5V/3A) converter module, which is wired directly to the 12V battery:

enter image description here

Now thinking of replacing the above PWM modules with OPTOCOUPLER isolated ones like the LR7843 (max 30V/161A) which seems to address the flash back current problem that I suspect is happening with the current cheap PWM modules (which do not have an optocoupling feature).

  • \$\begingroup\$ Do you have any documentation on the PWM board? \$\endgroup\$ Jul 9, 2020 at 22:35
  • \$\begingroup\$ Thanks for your interest in my Q. Unfortunately, this is a very cheap Chinese PWM so I don't have much. Here is the product in question: aliexpress.com/item/4000002805230.html \$\endgroup\$
    – that-ben
    Jul 9, 2020 at 22:36
  • \$\begingroup\$ According to the illustration on the website, with the terminal blocks up, power input should be on the left,and output to the motor on the right terminal block. You appear to have that wired backwards. \$\endgroup\$ Jul 9, 2020 at 22:43
  • 1
    \$\begingroup\$ How are you grounding your RPi? \$\endgroup\$
    – user105652
    Jul 9, 2020 at 23:12
  • 1
    \$\begingroup\$ You need to try to make a proper schematic diagram. That is part of learning about electronics. As it is, anyone who wants to help you first has to translate your unclear wiring diagrams into schematic diagrams. tlfong01 has tried to do that for you, but has either made a mistake or else you are doing some very strange things indeed. Help us to help you: Trace out your circuits and draw proper schematic diagrams. If you are on a PC, then you can use the CircuitLab editor built into the site editor. Edit your question, then click on the circuit diagram button. \$\endgroup\$
    – JRE
    Jul 10, 2020 at 10:18

1 Answer 1



The OP is learning how to use Rpi to control a 12V DC motor using a 5V relay without any optical isolation. To adjust motor speed and direction, He uses a PWM controller and a DPDT reverse polarity relay to switch the 12V power supply.

So far so looking good, but he has already fried two Rpi's!

Now the OP has two questions:

(1) That it might be the "back EMF" flash back current that fries his two poor Rpi's, and what sort of fly back diodes should be used to prevent frying his third Rpi?

(2) Or using an optocoupler might help to isolate any noises or spikes from going back to Rpi and cause trouble?

Short Answer

relay pwm 1

fake pwm module

Note: The schematic v0.3, after a wild guess.

WARNING: I am just a friendly hobbyist. No guarantee no nothing won't melt down or blow up.

Flyback Diode Notes

Schottky Diode

/ to continue, ...

Long Answer

/ to continue, ...


(1) AOD4184A 40V N-Channel MOSFET datasheet - Alpha and Omega

(2) IRLR7843PbF IRLU7843PbF HEXFET (30V, 3.3mΩ, 34nC) Power MOSFET - IR (tlfong01's remark: doesn't seen like a Schotky flyback diode)

(3) AliExpress High Power 15A 400W MOS FET Trigger PWM Drive Module Control Panel Controller - US$0.50 tlfong01's remark: Just one "channel" unidirectional high current switch, nothing to do with PWM, though you can use 20kHz (Electromechanical relays can only do 10Hz) PWM signal to do the switching!

(4) IRLR7843PbF IRLU7843PbF HEXFET (30V, 3.3mΩ, 34nC) Power MOSFET - IR (tlfong01's remark: doesn't seen like a Schotky flyback diode)

(5) Flyback Diode Selection Guide 1/2 - tlfong01, rpi.org.forum, 2019mar06

(6) Schottky Diode Selection Guide 2/2 - tlfong01, rpi.org.forum, 2019mar06

(7) How to protect GPIO from back current? Diode? - that-ben 2020jul20

(8) AliExpress High Power 15A 400W MOS FET Trigger PWM Drive Module Control Panel Controller US$0.50

(9) How to wire a PPTC polyswitch + blown indicator LED to protect a bi-directional DC motor from stalling? - that-ben, Rpi SE 2018may01

(10) Rpi GPIO pin's High level signal possibly not High enough to switch off the 5V relay problem - that-ben, EE SE 2018may01

(11) How to properly use a relay module with JD-VCC from Arduino/Raspberry? - Carlos Garcia, EE SE 2020jun13

/ to continue, ...

  • 2
    \$\begingroup\$ Are you sure about the PWM driving the coil of the relay? That looks like a very good way to ruin a relay. \$\endgroup\$
    – JRE
    Jul 10, 2020 at 12:25
  • 1
    \$\begingroup\$ @tlfong01 FYI, the relay is a 3.3V control one (not 5V). There is absolutely nothing connected to any of the 5V rails on my Rpi. Not sure if it changes anything in the schematic. \$\endgroup\$
    – that-ben
    Jul 10, 2020 at 12:43
  • 1
    \$\begingroup\$ There is no 5V relay anywhere in my project. The Rpi relay (marked BESTEP) is control 3.3V and outputs 12V to the inverse polarity relay which is control 12V output 12V. \$\endgroup\$
    – that-ben
    Jul 10, 2020 at 13:02
  • 1
    \$\begingroup\$ OK but it's not the case with my relay. It's a JQC3F-03VDC-C (3.3V). There is zero 5V rail anywhere in my project. On the FIRST version yes there was a 5V relay and a 5V rail, but those have been replaced in the SECOND version as shown in Q. \$\endgroup\$
    – that-ben
    Jul 10, 2020 at 13:57
  • 1
    \$\begingroup\$ Ah, I overlooked that your relay is actually 3V3, not 5V. My apologies. I will correct the error later. Cheers. \$\endgroup\$
    – tlfong01
    Jul 10, 2020 at 14:01

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