I am trying to follow an Audrino tutorial with my kid and I am confused by the role of the diode in this circuit.

In particular, I have the following questions:

  1. It looks like the circuit will work without the diode. The purpose seems to be to allow the current flow from the pin9 power source, but why do we need that?
  2. Does current flow from pin 9 through the emitter to the ground?
  3. More generally, when someone says “the current” is in this direction, do they mean that is the + => - direction, or the flow of the electrons?

enter image description here

  • 3
    \$\begingroup\$ A transistor may have a current gain >>100 but as a switch it can drop to 10% of its linear gain very quickly when switch drops from 1V and below across it. So the base resistor needs to be reduced greatly. e.g. <1k \$\endgroup\$ Commented Dec 29, 2019 at 6:04
  • 3
    \$\begingroup\$ When the magnetic field around the coil collapses, the voltage is reversed and can also spike to levels that would destroy other parts of the circuit. The diode provides a current path when the voltage across the motor reverses, preventing damage to the transistor. \$\endgroup\$
    – jwdonahue
    Commented Jan 14, 2020 at 3:29

6 Answers 6

  1. The diode in this configuration is called a "flyback" diode. A motor consists of a coil of wire which is effectively an inductor (and an electromagnet). As the motor spins, the coil will be turned on and off with the commutator inside the motor which will cause voltage spikes. The diode provides a path for this energy so that it can be dissipated into the +5V rail rather than going somewhere else less predictable. You'll also find these diodes across relay coils. Usually you'll also put a capacitor on the 5V rail to further absorb the spikes (otherwise you'll get noise everywhere). NOTE: Your question says "Pin 9 power source". That is incorrect, see the next question.

  2. Yes, but not very much current. That's the purpose of this circuit. Very little current (uA or mA) can be used to control a motor (~200mA with that transistor from +5V through the motor). Only about 330uA (closer probably to 270uA...I haven't typed any numbers into a calculator) will flow from Pin 9 into ground through the transistor. The current for the motor comes from the +5V rail.

  3. That is correct. When talking to someone, current always flows from high potential (+) to low potential (-), even though the electrons are going the opposite direction. Really it's just a convention so that all the signs work out.

  • 1
    \$\begingroup\$ Wow, this is a terrific and extremely well replied answer. Thanks a lot! I understand much better now. \$\endgroup\$
    – meow
    Commented Dec 29, 2019 at 5:05
  • 1
    \$\begingroup\$ One thing, is it possible in a transistor for current to flow from base to collector? \$\endgroup\$
    – meow
    Commented Dec 29, 2019 at 5:06
  • \$\begingroup\$ yes it is, such current also tends to make the emmiter-collector path conduct in the reverse direction if there's an opportunity for that. \$\endgroup\$ Commented Dec 29, 2019 at 8:57
  • \$\begingroup\$ Additional remark on 3: On the mesoscopic level what matters is current density, not current. And since current density is defined as charge density times velocity (j=rho.v) and electrons are negatively charged by convention, current density (and thus current) always points in the opposite direction of electron movement. Nowadays it might seem that electron movement was a more natural reference for current for most cases. But the charge convention (electron = negative) was met when people didn't even know that there are electrons and atom bodies which cause the phenomenon of electric charge. \$\endgroup\$
    – oliver
    Commented Dec 29, 2019 at 17:09
  • \$\begingroup\$ You will see a similar diode arrangement when a transistor circuit drives a magnetic relay. \$\endgroup\$
    – Hot Licks
    Commented Dec 30, 2019 at 2:55

To understand this trick, a beginner needs to imagine what the voltages are (magnitude and polarity), and where the currents flow (direction and path). I know this from my personal experience; that is why, I have visualized these invisible electrical quantities in the pictures below by voltage bars (in red) and current loops (in green). I have considered the similar but simpler configuration with an inductor (e.g., a relay coil) but it can be applied to the motor as well.

Suppressor diode

1. The key of intuitive understanding inductive circuits is to think of the inductor as of a "rechargeable current source". So, when the transistor T is turned on (Fig. 1), the supply voltage is applied to the inductor L and it begins charging. The current \$I_{CH}\$ gradually increases from zero to its maximum (determined by the internal coil resistance). Note the sign of the voltage at the inductor input is positive since it acts as a load.

2. When the transistor turns off (Fig. 2)... and there is no diode connected, the inductor, behaving as a current source, "wants" to pass the same current. First, it reverses the polarity of its internal voltage \$V_L\$ (back emf); then, as the circuit is open, it begins increasing this voltage with the hope to pass the current through the transistor. Thus its voltage exceeds many times the supply voltage and adds to it. It is as if the transistor is supplied by a very high-voltage compound power supply... and if its maximum voltage is not high enough, it will break.

3. If a diode D was connected in parallel to the coil (Fig. 3), it will provide a path for its current \$I_{DSCH}\$... and the coil will quickly disharge through it. Now the supply voltage is limited only to \$V_{CC} + V_F\$, which is safe for the transistor.

  • 8
    \$\begingroup\$ Wow, those diagrams look almost like computer graphics. Impressive precision! I’d like to see your soldering work ;) \$\endgroup\$
    – Michael
    Commented Dec 29, 2019 at 12:28
  • 3
    \$\begingroup\$ @Michael, I hope you think the same about the content:) I would use the build-in schematic editor if only I find a way to draw these colorful means helping understanding. In the past, I was using Corel Draw and Flash Animator but they were quite cumbersome. BTW your responce is the first admiration for my "art" work; in most cases I am punished with negative votes for this... \$\endgroup\$ Commented Dec 29, 2019 at 14:01
  • 3
    \$\begingroup\$ I think the "rechargeable current source" is a misleading analogy. When we talk about common rechargeable voltage sources we assume that the current can be stopped and the rechargeable device will store energy indefinitely, without the flow of current. That's not how the inductor works in this circuit, and I think you oversimplify the situation to make it fit your analogy. I think the reader is better served by talking about the true behavior of inductors, rather than anthropomorphizing them...the inductor doesn't "want". \$\endgroup\$ Commented Dec 29, 2019 at 14:22
  • 3
    \$\begingroup\$ Analogies help understanding, empathy also. Note I have not said "it is a recheargable current source"; I have said "think of it as of a recheargable current source..." and also closed it in quotes. We charge a capacitor by "pushing" current through it; when removing the current source, it becomes a voltage source. Similarly, we charge an inductor by applying voltage; when removing the voltage source, it becomes a current source. If the capacitor is a "recheargable voltage source", why not the inductor is a "recheargable current source"? If it somehow helps understanding, let's use it. \$\endgroup\$ Commented Dec 29, 2019 at 14:51
  • 3
    \$\begingroup\$ Thank you @Circuitfantasist for the "rechargeable current source" analogy for an inductor. That's a great way to conceptualize inductors. \$\endgroup\$
    – JS.
    Commented Dec 30, 2019 at 17:27

As a slight aside, I thought I should amplify Tony Stewart's comment.

The circuit you're looking at is perfectly fine in principle, but it cannot be used for any but the smallest motors.

Put it this way - in order to get much current (and therefor much torque or power) from the motor, you need the voltage to be as close to 5 volts as possible. This means that the voltage across the transistor (Vce) must be as low as possible, and certainly less than 1 volt. In addition to this obvious issue, keep in mind that the power dissipated in the transistor is the product of the voltage (Vce) and the current (mostly collector current).

This is perfectly possible, but there are limits. The most important is that, when the transistor is being operated with very low Vce (less than a volt, typically), its gain drops significantly. The general rule of thumb for this condition, called saturation, is a gain of 10 to 20, where you've got a choice of exactly how optimistic you want to be. The conservative value is 10. At this value, you can expect Vce's of about 0.2 volts or so - as long as you respect that this implies a specific current level.

Now look at your circuit. If pin 9 has a maximum voltage of 3.3 volts, the voltage across the base resistor will be about 3.3 - 0.6 volts, or about 2.7 volts. The 0.6 comes from the base-emitter voltage drop. 2.7 volts divided by 10k gives a base current of about 270 uA. Driving the base with this current gives a maximum collector current of about 2.7 mA, or 5.4 mA with a saturation gain of 20. If the transistor is fully "ON", Vce will be about 0.2 volts. So the maximum power available for the motor will be about 4.8 volts times 2.7 to 5.4 mA, or something on the order of 13 to 26 mW. Just as a reference point, 1 horsepower is about 750 watts, so you're talking about 17 to 34 micro-horsepower.

This is hardly useless; you can spin a little indicator just fine with a low-power motor. It's just that you won't be able to make (for instance) any sort of vehicle, nor will you be able to lift much in the way of loads with a pulley.

If you do want actually build your circuit, what do you need for a motor? It will need to be rated for 5 volts or more, with as close to 5 volts as you can find. Buy yourself a cheap DMM (digital multimeter) for 10 to 20 bucks and measure the resistance of the motor. It will need to be on the order of 900 to 2k ohms or greater. Resistance equals voltage over current. 4.8 volts divided by .0027 to .0054 will give you the numbers (remember that we were talking mA, not amps).

Obviously, you can get more current by driving the transistor harder, and you do this by reducing the base resistor. However, be aware that at some point the Arduino will not be able to drive enough current from pin 9, and the voltage at the pin will start to drop. You should be fine with reducing the resistor to 1k, and possibly to the vicinity of 330 ohms or thereabouts, with a consequent increase in transistor (and motor) current. I encourage you to investigate this in a systematic way. When you do, also check the temperature of the transistor on a regular basis. 2N3904s are not high-power devices, so don't be surprised if it gets hot. Fortunately, they are also really cheap, so don't get too paranoid about burning a few out.

In the worst case, you will learn about Magic Smoke. Did you know that transistors actually work by magic? At the center of each transistor is a little pocket of Magic Smoke. If you let the Magic Smoke out, the transistor will stop working, and this proves that the Magic Smoke made it work.


  • \$\begingroup\$ Maybe a power MOSFET will solve the problem? \$\endgroup\$ Commented Dec 29, 2019 at 17:11
  • 1
    \$\begingroup\$ @Circuitfantasist yes, substituting a moderate size N-FET for the NPN would allow use of a somewhat larger motor. \$\endgroup\$ Commented Dec 29, 2019 at 20:52
  • 1
    \$\begingroup\$ @Circuitfantasist - Yep. FET is the standard answer. However, it must be what is called a "logic-level" FET. This means that it can be driven with gate voltages of 5 volts or less. A "regular" MOSFET will need (typically) 10 volts or so on its gate to drive a high-current load. \$\endgroup\$ Commented Jan 2, 2020 at 19:25

In answer to your questions, while the circuit will work without the diode, its purpose is to protect the delicate electronic components from very high voltage surges coming from the motor when it shuts off. You see, the windings of the motor act, not only as an electromagnet, but also as an inductor, which stores a great deal of energy in its magnetic field. When the power supplied to the motor shuts off, that field collapses, and dumps all its stored energy back into the circuit in one big surge, which can damage the electronics components. So, the diode then acts as a "short circuit" for the motor, providing a path for the windings to discharge, much like a bleeder resistor across a large capacitor.

Next, regarding the direction of current, historically, current was considered to flow from points with + charge to those with - charge, however, it was eventually discovered that electrons themselves do, in fact, flow from - to + points. This concept is referred to a "electron current", while the original idea is called "conventional current".

Since the formulas used to calculate electronic values were devised using the wisdom of the time, "conventional current" is still widely used when designing new circuitry.

Therefore, it would be more correct to say that current flows from ground, through the emitter to pin 9, though, in reality, the distinction is rather academic; whichever you believe, it "just works". Hope this helps - keep learning & enjoying this fascinating field of study!


All the answers here stress that inductive loads like a motor carry a load of energy that the flyback diode discharges. This is not what happens here, and flyback diodes will be comparatively small devices obviously not being able to emit a lot of energy.

What is at stake here is that switched-off inductors add as current sources, maintaining their current current. Even if this current is low, if it has infinite resistance to work against, the resulting voltage can become arbitrary large, like a static discharge when walking across some plastic fibre carpet. It's the resulting voltage alone that destroys circuits.

The flyback diode provides a path for the current to keep flowing. Since the voltage across it is low (ideally zero), not much energy gets destroyed here: the bulk dissipates in the resistance of the motor coils. However, depending on the size and type and load of motor, the motor may act as a rather large inductance since it does not feed back just electrical field energy but also mechanical energy back to its inputs when switched off. Generally, the flyback diode would be dimensioned similarly to the driving transistor.

The thing to remember that shortcircuiting an inductor is its idling mode while an open circuit is forcing the stored energy out of the magnetic circuit of the inductor immediately. So the flyback diode is not just protecting the driving transistor but also the inductor itself which might otherwise have sparks breaking through the isolation of its coils and thus damaging it.

  • \$\begingroup\$ @user239212, very reasonable thoughts... I like them... and I like the way you think. I would add that the maximum current through the diode is the same as the maximum current through the transistor. Both transistor and diode act as complementary switches that steer the current between themselves. \$\endgroup\$ Commented Jan 1, 2020 at 13:27

Say that the motor is spinning a flywheel.. When the power is turned off the diod bleeds back the energy back thru the coils of the motor to short out or cancel out generated electricity.

  • \$\begingroup\$ The same diode would be used with a relay coil. The issue is the switched inductance, not the rotation of the motor. \$\endgroup\$ Commented Dec 30, 2019 at 16:50

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.