Could you help me explain the two circuits below in some details please (relay and solenoid valve example). I want to make sure I know every aspect of it, especially the flow of electricity when the solenoid is turned on and off, which direction is the flyback current created and how exactly the rectifier diode protects Arduino from it when the solenoid is de-energized (I want to confirm my understanding of it is correct at every bit). Thank you very much.
Firstly the base resistor is needed to limit base current (Vbe is around 0.7V, you
should never exceed base current ratings). The base current level should be about
1/10th to 1/20th of collector current for most small switching transistors. Collector
current depends on the winding resistance.
The diode is wired so that the inductor current can continue to flow when the transistor
switches off. Inductors give current momentum, so it cannot suddenly be stopped (if
you try this, the voltage will rise to whatever level it takes to force the current to keep
flowing). The current that was flowing from +ve supply through the coil to the transistor
gets steered to go round and round via the diode and coil when the transistor switches off,
but the amount of current decays exponentially depending on the inductance of the coil
and the forward voltage of the diode.
Without the diode attempting to turn the transistor off will cause the coil to punch
the current through the transistor by brute force (voltage). The current decays much more
rapidly with higher voltages, but the damage is done (remember logic signals and switching
transistors are optimized to turn on and off as fast as possible).
With the relay driving the solenoid you just have two similar circuits - a switching device
and a coil in each, so diode needed in each case. The second diode reduces spark damage
to the relay contacts and prolongs their life, the first diode stops the transistor being
utterly destroyed.
In all 3 cases, when current starts to flow from positive to negative, the change in current flow causes a magnetic field to be created within the inductor. When current stops flowing, the magnetic field collapses, and the change in magnetic field creates a current flow. The diode gives the a induced current a path to dissipate, vs creating a large voltage spike across the high resistance of the transistor (Ohms Law: Voltage = Current x Resistance).
CrossRoads:
When current stops flowing, the magnetic field collapses, and the change in magnetic field creates a current flow.
That could be a trifle confusing - "stops flowing"; "creates a current flow".
I would prefer to say "if the main circuit is broken" and explain the various consequences from there. Emphasis should be put on the fact that the current continues to flow in the same direction (by whatever route).
Paul__B:
I would prefer to say "if the main circuit is broken" and explain the various consequences from there. Emphasis should be put on the fact that the current continues to flow in the same direction (by whatever route).
Thank you guys, that's what I heard the reason to add the rectifier diode across the coil. I just got confused which way I should connect the anode and cathode of the diode across the coil ... So when the created current tries to flow in the same direction, I should connect the anode of diode to the lower bottom of the coil (referring to the first attached picture), because basically now the coil is acting like a battery, so the current will flow downwards and herein I should connect the anode of diode to it as rule of 'positive to positive', right ?
Key points
"the induced electromotive force in any closed circuit is equal to the rate of change of the magnetic flux through the circuit."
"When the electric current in a loop of wire changes, the changing current creates a changing magnetic field."
So a large rapid change in current creates a large induced electromotive force (voltage). Without the diode, when the switch opens, current stops flowing (a rapid change in current). This results in large voltage spike that can damage components. The diode prevents this by allowing current to keep flowing through the coil after the switch is open.