# Relay current flow

I'm new to electronics.

I found the tutorial about the control of a relay using GPIO in raspberry pi from http://arnholm.org/raspberry-pi-controlling-a-relay/ . It has the following electric circuit :

I wonder the existence of the diode laid down parallel with relay. I searched about this and got the answer from Why is there a diode connected in parallel to a relay coil?

Since an inductor (the relay coil) cannot change it's current instantly, the flyback diode provides a path for the current when the coil is switched off. Otherwise, a voltage spike will occur causing arcing on switch contacts or possibly destroying switching transistors.

It says eventually when the switch is off, the flow of relay current should go through the flyback diode to prevent destroying the switching transistor because it causes the undesirable spark on it.

But I am worried about if the relay current from REL1 go through D1 diode, the sudden excess of current might make the pi die after the current going up above the diode.

So I thought one of the solution is if we put 2 diodes in the position D1 and draw a line between them, we can release the current safely.

So my question is

What if we put a resistor above the D1 diode? Does the current can be attenuated with dissipation in the resistor? Can this be also a solution?

• They say "don't do this bit" because that relay would need to be listed as equipment (not components) in mains power switching. The UL listing on a relay from Mouser is a "component" listing, not sufficient. Contrast with a RiB relay, which starts with a listed component, but packages it to work in mains wiring methods, and has achieved UL listing as equipment for direct mains use. I wish someone would make more stuff like this for the Raspberry Pi'ers of the world. – Harper - Reinstate Monica Mar 26 '18 at 18:56
• voltage spike will occur causing arcing on switch contacts .... it does not refer to the relay contacts in your diagram ... if you used a smaller relay, instead of the transistor, to drive the main relay, then the note about arcing would refer to the contacts of the smaller relay ... arcing would happen because of the inductive load of the bigger relay coil – jsotola Mar 26 '18 at 19:24

This so-called arc from breaking the coil current Only occurs with the dry contact . The time could be in the nanosecond range and since V equals V=LdI/dt with dt going to zero V can arc on dry contacts. Because the transistor has some capacitance it cannot shut off that quickly so the diode is only to protect the transistor and there’s very little capacitance that would feedback any significant charge back to the microcontroller so no worries there .

The 100mA transistor current is immediately switched through the diode along the same wires can be handled easily by 100 mA small signal diode. The diode should be placed close to the transistor rather than the coil so that the current path is the same . For EMI pulse attenuation it’s best to have the switched current ground and power signals to the relay coil interface close together to minimize current loop area and antenna-like interference to high impedance nearby signals.

Furthermore 3 mA into the base is more than enough to saturate the transistor. The BC 337 will rise from 50 mV to less than 200 mV which is within 5% of your 5 V supply with only one milliamp of base current @Ic=100mA

That sudden excess of current flows only through the diode and the relay coil, hence it has no influence on the rest of the circuit, provided that the diode is close to the relay coil pins.

What might cause some harm is that the transistor is switched of, and it suddenly draws less current from the 5V supply. If you are worried aboyut this you could put a beefy capacitor (for instance 470uF) between gnd and 5V. (Or, when you have multiple relays, use a separate 5V supply for the relays.)

With a Pi this effect will be less pronounced, because most (all?) Pi circuitry is powered by a switcher that converts the 5V to 3.3V.