I'm going through the Adafruit Motors guide for Arduino, found here, and I'm struggling to understand how each of these parts play in. From what I understood, pulse width modulation is basically a way to send varying levels of power through a digital output source. Additionally, it seems that the guide is using a transistor with the PWM signal as the gate, so it can allow the percentage given by the PWM signal to control how much flow is given to the motor. However, what I'm confused here is that both the power and ground are interfacing with this transistor/diode setup.

This is more specifically what I mean, on the bottom seems really simple: the PWM signal comes on the yellow wire, fed through the resistor so that it doesn't fry the transistor into the gate.

After this though, there's a ground signal being passed into the source leg of the transistor, and the sink leg is connected to both a diode for power AND the ground of the motor? I might be misunderstanding how a diode works but this doesn't seem to make sense as to why the ground signal is being modulated.

enter image description here

My initial thought for this would be a system where only the power of the motor is varied by the PWM signal, sorta like in this way (apologies for the terrible drawing style, I haven't gotten used to some of the Arduino sketching software online):

enter image description here

I've not gotten to try this yet, but I assume it wouldn't work or would destroy components somehow since this does seem to be a simpler solution, and it's not being used. I was sorta trying to figure out 1) why my solution would be bad and 2) how the official solution works, as they haven't really given any actual schematic (not that I would understand it, haha) Any help would be appreciated! Thanks!

  • Tip: the blue line "going up" that you marked GND, is not really GND but one of the motor connections. The motor is connected between 5V and the diode's Anode (and the transistor's collector). You can use the integrated schematic editor to make a clearer drawing.
    – StarCat
    May 17, 2021 at 17:52
  • There's a schematic on the transistor page. May 17, 2021 at 17:53
  • do keep in mind that electrons flow from negative to positive, so it does modulate the source of power as shown.
    – dandavis
    May 20, 2021 at 21:13

2 Answers 2


I think your confusion does indeed stem from the diode. You can forget the diode, it doesn't feature in the switching of the motor. When a motor runs it can generate large negative voltages caused by the repeatedly collapsing magnetic field. The diode, which is connected backwards, exists to take those negative voltages and prevent them damaging the rest of the circuit.

The transistor arrangement in use is called common emitter, and is also known as a low-side switch when used in saaturation between the load and GND, as in this situation. It doesn't matter to the motor if you have the switch between the motor and GND (using an N-channel MOSFET or NPN bipolar transistor) or between power and the motor (using a P-channel MOSFET or PNP bipolar transistor), but it does matter to the Arduino.

It is harder to switch a "high side switch" from an Arduino, especially if your power supply is higher than the voltage the Arduino runs at. Since the switching is controlled by the difference in voltage between the "common" point (emitter [BJT] / source [MOSFET]) and the switching signal (Arduino), which is limited to 5V, any "common" point voltage that is higher than that is unreachable by the switching signal, so ends up in being always on and the switching fails.

It is possible to switch the high side, but you need an extra driving stage to allow the higher voltage switching.

For this specific circuit where the power is 5V it's not as susceptible to the problem, but this is a rare case. Normally you will be driving motors at a higher voltage, such as 12V, and there you will need an extra driving stage, or just use the far simpler low-side switch arrangement this circuit teaches you.

  • this makes a lot of sense but I had one question regarding that flyback diode, does it matter whether the end of it feeds back into the pulse-modulated ground or could I feed it back into a normal ground wire?
    – Daneolog
    May 17, 2021 at 19:19
  • 1
    @Daneolog Not sure what you mean there--it needs to be explicitly across the motor since it's the motor generating the negative voltage. May 17, 2021 at 19:25
  • Its purpose is to form a circuit between the two pins of the motor in reverse.
    – Majenko
    May 17, 2021 at 19:30
  • oh yeah no I meant like, the other side of it, that's pointing at the same line as the transistor's output, is pointing to a modulated ground
    – Daneolog
    May 17, 2021 at 19:30
  • oh, I see, so it's not just a means of emptying out all the negative energy into a ground, it's feeding it back in
    – Daneolog
    May 17, 2021 at 19:31

Your schematic

The blue line in your first schematic "going up" that you marked GND, is not really GND but one of the motor connections. If you look at the Adafruit schematic you can see this.

The motor in the Adafruit schematic in the link you provided is connected between 5V and the diode's Anode (and the transistor's collector).

Flyback diode

The diode is a so-called "flyback diode", connected between the motor connections to "soak up" back-EMF that occurs when the motor is turned off and its magnetic field collapses. If the diode would not be there, there would be a voltage spike on the transistor's collector, possibly damaging it.

Low-side switching

The "Adafruit" solution uses an NPN transistor as a switch on the low side of the motor when the I/O pin is high, like the schematic on the right. This is a very common setup as it has almost no disadvantages.

High-side switching

Your own suggestion (called high-side switching, shown on the right) would work as well (with the addition of a flyback diode) but it would need a different type of transistor, a PNP transistor. Also, the I/O inputs would work in an inverted way: when the I/O pin is low, the motor will be on and when the I/O pin is high, it will be off.

Note that high-side switching will only work when the supply voltage is lower or equal to the voltage that's on the I/O pins. You can't turn on a 12V motor this way, for example. With low side switching, you will not have this problem and you can switch higher voltages.


simulate this circuit – Schematic created using CircuitLab

  • ohhh, I see. so basically motors can run both ways, if you block ground by a specific amount, it would block movement by that amount in the same way you blocked power by that amount, but the method of blocking ground is easier because it allows you to have the same setup for any size motor, just having a power source strong enough for the motor. that makes lots of sense! thank you so much!
    – Daneolog
    May 17, 2021 at 19:16

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.