Don't we all love how this whole MCU business is playing out, with those GPIOs, providing us with super-powers - the word alone - "GPIO" - sends shivers of joy down the spine of every maker. But wait - it's just 3.3 volts.
Yeah no problem, just add a logic level shifter from 3.3 to 5V, then try to run your motor driver board with 5 Volt signals to power 12 Volt motors, it might work. I actually did that, controlling 12V 1 Amp Steppers via Darlington NPN transistors, back then connecting the 5 Volts of the printer port over a protection diode and a resistor directly to the base of the transistor - it worked. Later I slapped together an 8 channel 3.3V to 5V logic level shifter, with 2 MOSFETS per channel, so I could use my 5V "Driver" board on a Raspberry Pi Zero - it worked too. But frankly the whole thing became as big as a shoebox, and I felt it was clumsy and over-complicated.
If there were only a simple solution, to drive any load with minimal fuss and investment, from a 3.3 volt GPIO. So I sat down and re-imagined the whole scenario. After some tinkering in simulation and successful practical tests I finally came up with a working design that I am actually even a bit proud of so that I want to share it with you guys, here and now.
First, to see how simple it is, the BOM (for 1 channel):- 2 LEDs (red clear dome, super-bright, 20 to 100 mA)
- 1 Resistor 100 ohm
- 1 Resistor 10 Megaohm
- 1 N-Channel MOSFET (I used BUZ 71A, but other N-MOSFETs may work just as well. Simple NPN transistors won't work.)
And that's it. These few components will provide us with the following functionalities:
- Non-inverting Logic Level-shifter (1-directional) from 3.3v to 12 volt or any other wanted voltage (maybe below 24V?)
- Opto-Coupler for full MCU protection
- Unlimited current control for bigger loads (still limited by the MOSFET, naturally)
Notice my choice to implement also Opto-Coupling was rather because it made the whole level shifting simpler, than it was to protect the MCU, but of course additional protection is welcome.
To use this circuit, you will also need: an MCU that has 3.3v GPIOs, a powersupply to power the load, eg. 12V Laptop supply, a powersupply for the MCU, some wires and soldering and/or PCBing equipment, and finally a test load, such as a 12 V DC motor. Of cource you can also use some other output voltage, like a 9V motor and supply. Or run a 12 V motor with 6 V at low power. Whatever you fancy.
Now, when you look at my schematic you may think I am a fool who put the LEDs the wrong way into the circuit - nothing could be further from the facts. Few people know that an LED can be used as a Light sensor - when light shines into an LED then it produces a tiny reverse current. That means you will read about 20 to 40 millivolts at the positive terminal (meaning, where it normally would sink the positive supply, it now wants to source its generated current).
What happens in this circuit therefor is: with no light falling into the sensor LED it will be just a blocking diode, and the 12 volts that are coming from the 10 Mega-Ohm resistor will ignore this path, and hence go to the MOSFET Gate and fully unblock the connection from Drain to Source, so the motor gets full power because now the current can flow to ground.
On the other hand, if enough light falls into the sensor, it will generate a reverse current with about -40 millivolts - not much, but enough to make this LED look like Ground to the 10 MOhm resistor, hence the tiny current from the latter now prefers to flow through the LED right into ground, and therefor the Gate of the MOSFET sees zero volts, causing it to block the flow from Drain to Source completely.
Notice the sensor is working in reverse logic: when it sees no light then the motor is powered, but when light falls into it, to motor stops. We could just live with it and always make sure to power on the MCU and program first, and the motor power supply later. Handle it in software and always keep the LEDs on when motors should not move. Still, it bears the risk of motors running wild if - for some reason - the emitter LED is off when the Motor power supply is turned on. I don't like that.
To solve this in a simple way and get non-inverting logic, we can do the following:
The Emitter LED isn't powered by the GPIO, but rather does the GPIO work as a sink for it, or you could call it a dynamic pseudo-ground, all while the LED is powered by a permanent 3.3V source. This way we can still turn the LED on and off by the GPIO, but now the LED is on when we write "0" to the pin, and off when we write "1". That's because "1" is 3.3 Volt, and there cannot be any current flow between a 3.3 Volt supply and a 3.3 Volt GPIO. Yet, if the GPIO is set to "0", it is practically at zero volts, therefor the current from the 3.3 volt supply now flows through the LED into the GPIO, and the LED lighs up. Keep in mind the amount of current a GPIO can sink is limited, on ESP32 it is 28 mA at 3.3V.
While the steady 3.3 V supply for the emitter diode could be provided by the MCU itself, for the reasons explained above I would rather suggest it be provided by the 12V source (or 12V and 3.3V have a shared source that is switched instead), to make sure the emitter-LED is always on whenever the 12 V source is on.
The MOSFETs I used are BUZ 71A, sold between 70 cents and 4 bucks, tho I found a bag of 90 pcs at a garage sale for 3 bucks. The LEDs are also cheap when bought by the 100s, just like the resistors, so I'd locate this device without a PCB at probably 1 dollar per Channel.
I'm planning to use it with 4-phase steppers, because using 2-phase steppers would additionally require some kind of H-bridge, which in the version containing short-circuit-protection requires at least another 5 MOSFETS or Transistors for every motor, where 4-phase stepper motors work with positive voltage only and can be connected directly to this NIOCLLHLPU (non-inverting opto-coupled logic-level-shifting-heavy-load-powering-unit). You ain't got no NIOCLLHLPU? Everybody has a NIOCLLHLPU these days. j/k.
And that surprisingly already concludes my elaboration on the subject matter. I hope this circuit is as useful for anybody out there as it is for me. And have Merry Christmas everybody.






Comments