Electro-Magnetism for tinkerers

Electro-Magnetism for tinkerers

April 12, 2026

TL;DR

Before tinkering with electronics, how about understanding what we are doing?

Intro

Lately, I was getting surprised on how neccesary a Diode is to avoid EMF blowing up such systems.

Maxwell’s Equations: $$ \begin{aligned} \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \ \nabla \cdot \mathbf{B} &= 0 \ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \ \nabla \times \mathbf{B} &= \mu_0 \left( \mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \right) \end{aligned} $$

Maxwell’s equations are essentially the “Four Commandments” of electromagnetism.

They describe how electric fields, magnetic fields, charges, and currents interact.

1. Gauss’s Law (Electricity)

$$\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}$$

Integral form:

$$\iint_{\partial V} \mathbf{E} \cdot d\mathbf{A} = \frac{Q_{enc}}{\varepsilon_0}$$

For a single point charge, that becomes the inverse-square field:

$$\mathbf{E}(r) = \frac{1}{4\pi\varepsilon_0}\frac{q}{r^2}\hat{\mathbf{r}}$$

What it means: Electric charges produce electric fields.

This law states that the “outward flow” (divergence) of an electric field from a volume is proportional to the charge inside it.

If you have a positive charge, field lines point away from it; if you have a negative charge, they point toward it.

2. Gauss’s Law for Magnetism

$$\nabla \cdot \mathbf{B} = 0$$

Integral form:

$$\iint_{\partial V} \mathbf{B} \cdot d\mathbf{A} = 0$$

Magnetic flux through a surface is:

$$\Phi_B = \int_S \mathbf{B} \cdot d\mathbf{A}$$

What it means: There are no “magnetic charges” (monopoles).

In electricity, you can have a lone proton.

In magnetism, you can never have just a “North” pole without a “South” pole.

Because of this, magnetic field lines always form closed loops—whatever goes out must come back in, making the total divergence zero.

3. Faraday’s Law of Induction

$$\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}$$

Integral form:

$$\oint_C \mathbf{E} \cdot d\mathbf{l} = -\frac{d\Phi_B}{dt}$$

For a coil with $N$ turns:

$$\mathcal{E} = -N\frac{d\Phi_B}{dt}$$

What it means: A changing magnetic field creates an electric field.

This is the principle behind power generators and wireless charging.

If you move a magnet through a coil of wire, the magnetic field changes over time, which “curls” (creates) an electric field that pushes electrons through the wire as current.

4. Ampère’s Circuital Law (with Maxwell’s Addition)

$$\nabla \times \mathbf{B} = \mu_0 \left( \mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \right)$$

Integral form:

$$\oint_C \mathbf{B} \cdot d\mathbf{l} = \mu_0 I_{enc} + \mu_0\varepsilon_0\frac{d\Phi_E}{dt}$$

where electric flux is:

$$\Phi_E = \int_S \mathbf{E} \cdot d\mathbf{A}$$

For a long air-core solenoid, the practical approximation is:

$$B \approx \mu_0 n I$$

With a magnetic core:

$$B \approx \mu n I = \mu_0\mu_r n I$$

What it means: Magnetic fields are created by moving charges (current) OR by changing electric fields.

Ampère originally figured out that current ($J$) creates a magnetic field (like in an electromagnet).

Maxwell added the second part: even if there is no physical wire, a changing electric field ($\frac{\partial \mathbf{E}}{\partial t}$) creates a magnetic field.

This addition was the “missing link” that proved light is an electromagnetic wave.


Why they matter together

When you combine these, you see a beautiful cycle: a changing electric field creates a magnetic field, which (if it changes) creates an electric field, and so on.

This self-sustaining loop allows electromagnetic waves (light, Wi-Fi, X-rays) to travel through the vacuum of space.

Which of these four feels the most intuitive to you, or is there a specific one that’s still a bit fuzzy?

The phenomenon you’re describing—often called inductive kickback or flyback—is primarily driven by Faraday’s Law of Induction, though it’s the result of a “disagreement” between Faraday’s Law and Ampère’s Law.

Here is how the physics plays out the moment you cut the power:

The Primary Culprit: Faraday’s Law

$$\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}$$

This equation tells us that a changing magnetic field ($\frac{\partial \mathbf{B}}{\partial t}$) creates an electric field ($\mathbf{E}$).

At circuit level, that shows up as the inductor voltage law:

$$v_L = L\frac{di}{dt}$$

And the energy stored in the coil is:

$$E_L = \frac{1}{2}LI^2$$

That stored energy must go somewhere when the switch opens. If the circuit does not provide a diode, TVS, snubber, or other path, the voltage rises until it finds one.

  1. The Setup: When the valve motor (which is essentially a big inductor/coil) is running, Ampère’s Law is at work: the current flowing through the coils creates a steady magnetic field.
  2. The Disconnection: When you flip the switch, the current tries to drop to zero instantly. This causes the magnetic field to collapse almost at the speed of light.
  3. The Kickback: Because that magnetic field is changing so rapidly (a massive $-\frac{\partial \mathbf{B}}{\partial t}$), Faraday’s Law dictates that a massive electric field must be generated to “oppose” that change.

The Supporting Actor: Lenz’s Law

While not one of the four main Maxwell equations (it’s actually wrapped inside the negative sign of Faraday’s Law), Lenz’s Law explains the direction of the kickback.

It states that the induced voltage will always try to keep the current flowing in the same direction it was going before the break.

What actually happens in the valve?

Since the circuit is now open (disconnected), that generated energy has nowhere to go.

The voltage across the switch or the motor terminals skyrockets—often to thousands of volts—to try and “push” the electricity through the air.

  • The Spark: If the voltage gets high enough, it ionizes the air, creating an arc (a literal spark) across the switch contacts.
  • The Damage: This “kickback” is why engineers put flyback diodes in parallel with motor coils. The diode gives that “kicked” current a safe path to loop back and dissipate slowly, rather than frying your electronics or pitting your switch contacts.

In short: Ampère’s Law built the magnetic “momentum,” and Faraday’s Law creates the violent “jolt” when you try to stop that momentum instantly.

Applications

How to avoid frying an ESP32 due to kickback

Even the simplest project has some meta-lessons and curiosities behind it.

Like this simple diode simulation:

After such investigation you also get interesting next steps.

After sich simple project you can continue that come back with more ad-ons.

Like pluggint it to a solar panel.


Conclusions

Beyond food and warm, do you have passions?

Got some projects that wanted to complete for long time…

but not sure on the how?