Magnets and electricity are fundamentally linked by electromagnetism: moving electrical charges generate magnetic fields, and changing magnetic fields induce electrical currents in conductors. This isn't just a textbook physics concept; it is the governing rule that dictates how motors spin, how transformers step down voltage, and why switching off a simple relay can instantly destroy a $10 microcontroller if you forget a 2-cent diode.

The One-Sentence Rule: Current creates a magnetic field, and a changing magnetic field creates a voltage. If the magnetic field is static, no electrical interaction occurs.

The Core Rule: Moving Charges and Magnetic Fields

When direct current (DC) flows through a straight wire, it generates a circular magnetic field around that wire. If you coil that wire into an inductor or a relay solenoid, the individual magnetic fields stack together, creating a concentrated magnetic flux. This is Ampere's Law in action.

The reverse is governed by Faraday's Law of Induction. If you move a permanent magnet past a coil of wire, or if you change the current flowing through an adjacent coil, the shifting magnetic lines of force cut across the wire's electrons, forcing them to move. This induced voltage is the basis of all power generation, from the alternator in your car to a 500MW hydroelectric turbine. For a deeper mathematical breakdown of these field interactions, Faraday's Law of Induction (HyperPhysics) provides an excellent foundational reference.

To understand how this affects a circuit, use the flywheel analogy: an inductor acts like a mechanical flywheel. A heavy flywheel resists changes in its rotational speed—it takes effort to spin it up, but once spinning, it takes immense force to stop it suddenly. Similarly, an inductor resists changes in electrical current. It delays the current when you turn the power on, and it violently pushes current forward when you try to turn the power off.

What Magnets and Electricity Change in a Real Circuit

In a purely resistive DC circuit, voltage and current scale linearly via Ohm's Law. But the moment you introduce a coil (a motor winding, a relay, a solenoid), you introduce inductance, measured in Henrys (H). Inductance adds a time-domain element to your circuit.

When you de-energize an inductive load, the collapsing magnetic field tries to maintain the exact same current flow. Because the circuit is now open (the switch or transistor is off), the resistance is nearly infinite. To force current across infinite resistance, the inductor generates whatever voltage is necessary. This is known as inductive kickback or back-electromotive force (back-EMF).

The Kickback Calculation:
Voltage Spike ($V$) = Inductance ($L$) × Rate of Current Change ($di/dt$)
If a 50mH relay coil carrying 100mA is switched off in 1 microsecond (0.000001s):
$V = 0.050 imes (0.1 / 0.000001) = 5,000 Volts$

That 5,000V spike exists for only a fraction of a microsecond, but it is more than enough to arc across transistor junctions, pit mechanical switch contacts, and punch through the thin gate oxides of modern silicon.

Where You Meet This in Practice

You cannot build functional hardware without dealing with the intersection of magnets and electricity. Here is where it dictates your design choices:

  • Relays and Solenoids: The coil generates the magnetic pull to move the armature. When the control signal drops, the collapsing field causes the kickback spike, requiring a flyback diode to safely recirculate the current.
  • DC and BLDC Motors: As the motor armature spins inside its magnetic field, it acts as a generator. This generates a back-EMF that opposes the supply voltage. This is why a motor draws massive stall current when jammed (zero back-EMF) but drops to a low running current at top speed (back-EMF nearly equals supply voltage).
  • Transformers: Two coils share a magnetic core. An alternating current in the primary coil creates a constantly changing magnetic field, which induces a proportional voltage in the secondary coil based on the turns ratio.
  • Switch-Mode Power Supplies (SMPS): Buck and boost converters intentionally use inductors to store energy in a magnetic field during the 'on' cycle and dump it into the output capacitor during the 'off' cycle to regulate voltage.

Real-World Scenario: The Inductive Kickback That Fried a Microcontroller

Let's walk through a classic bench failure that perfectly illustrates what happens when you ignore magnetic field collapse in a control circuit.

  1. The Setup: You are building a home automation node using an ESP32 DevKit v1. You need to switch a 120V AC water pump, so you use a Songle SRD-12VDC-SL-C relay. Because the ESP32 GPIO pins only output 3.3V at ~40mA, you use a 2N2222 NPN bipolar junction transistor (BJT) to switch the 12V relay coil. You wire the ESP32 GPIO to the transistor base, the 12V supply to the relay coil, and the other coil pin to the transistor collector.
  2. The Numbers: The relay coil has a resistance of 400Ω, drawing 30mA at 12V. Its inductance is roughly 50mH. The 2N2222 transistor has a maximum Collector-Emitter breakdown voltage ($V_{CEO}$) of 30V.
  3. The Outcome: You set the GPIO HIGH. The transistor saturates, the relay clicks loudly, and the pump turns on. Everything is perfect. Ten seconds later, your code sets the GPIO LOW to turn the pump off. The relay clicks off. Instantly, the ESP32's onboard LED flashes erratically, the serial monitor drops, and the chip reboots. When it comes back up, that specific GPIO pin reads 0.0V permanently, no matter what the code does. The pin is dead.
  4. What Went Wrong: When the GPIO went LOW, the 2N2222 cut off the current path in roughly 1µs. The 50mH relay coil's magnetic field collapsed, generating a 5,000V kickback spike to maintain the 30mA current. This spike easily exceeded the 30V $V_{CEO}$ limit of the 2N2222, causing avalanche breakdown. The transistor momentarily conducted the high-voltage spike backward into the ESP32's 3.3V rail, triggering a severe brownout and permanently damaging the silicon on that specific GPIO pad.

The Fix: Solder a 1N4148 or 1N4007 diode in reverse-parallel across the relay coil pins (cathode to 12V, anode to the transistor collector). When the spike occurs, the diode becomes forward-biased, creating a closed loop for the recirculating current to safely dissipate as heat in the coil's internal resistance. All About Circuits details the exact physics of why this recirculation path is non-negotiable for inductive loads.

Common Confusions: Flux, Field Strength, and Permanent Magnets

When reading datasheets for motors, sensors, or inductors, the terminology around magnets and electricity is frequently mixed up by hobbyists.

Term Symbol Unit What it actually means in practice
Magnetic Flux Φ Weber (Wb) The total 'amount' of magnetic field passing through a given area. Think of it as the total volume of water flowing through a pipe.
Magnetic Flux Density B Tesla (T) or Gauss (G) The concentration of the field in a specific spot. 1 Tesla = 10,000 Gauss. This is what a Hall-effect sensor (like the A3144) actually measures.
Magnetic Field Strength H Ampere/meter (A/m) The magnetizing force generated by the current, independent of the core material.
Inductance L Henry (H) The circuit's ability to store energy in a magnetic field per amp of current.

Another major point of confusion is the difference between permanent magnets and electromagnets. A permanent magnet (like a neodymium N52 disc) has a static, unchanging magnetic field. If you hold it perfectly still next to a coil, it induces exactly zero volts. It only induces voltage when it is physically moved relative to the coil. An electromagnet's field can be changed simply by altering the electrical current, allowing for stationary transformers and solenoids.

FAQ: Magnets and Electricity in DIY Electronics

Can a permanent magnet induce a steady DC voltage in a coil?
No. Faraday's law requires a change in magnetic flux. Moving a magnet into a coil induces a brief voltage pulse. Holding it inside the coil yields 0V. Pulling it out induces a pulse in the opposite polarity. To get continuous DC, you need a commutator (like in a DC generator) or active rectification.

Why don't AC motors and transformers need flyback diodes?
AC waveforms naturally cross zero volts 100 or 120 times a second. The magnetic fields are designed to continuously expand, collapse, and reverse in a controlled sinusoidal manner. The energy is transferred back and forth between the source and the magnetic field, rather than being abruptly interrupted by a hard mechanical or solid-state switch.

Does the physical core material change the inductance?
Drastically. An air-core coil might have an inductance of 10µH. If you wrap that exact same wire around a ferrite core with a relative permeability ($μ_r$) of 2,000, the inductance multiplies by roughly 2,000, jumping to 20mH. This is why switch-mode power supplies use ferrite or powdered-iron cores to achieve high inductance in tiny physical footprints.