
Use a 5V microcontroller board output pin with a transistor interface to control an electromagnetic switching module safely. Direct connection between a digital pin and the coil is unsafe because the coil commonly draws 60–90 mA, while a typical microcontroller pin supplies about 20–40 mA maximum. Insert an NPN transistor such as 2N2222 or BC547 between the control pin and the coil. Add a 1 kΩ base resistor to limit current from the I/O pin.
The coil requires a flyback diode placed across its terminals. Position the diode with the cathode toward the positive supply and the anode toward the transistor collector. This component absorbs voltage spikes that appear when the magnetic field collapses. Without this diode, spikes above 100 V may appear briefly and damage the microcontroller board.
Power for the switching module should come from a separate 5 V or 12 V supply if the coil current exceeds 70 mA. Connect the grounds of both supplies together so the control signal maintains a common reference. Many ready-made switching boards include an opto-isolator; this component separates the logic side from the high-current path and allows loads up to 10 A at 250 V AC or 10 A at 30 V DC.
A typical wiring layout contains four functional blocks: the microcontroller output pin, the transistor driver stage, the electromagnetic switch coil with protection diode, and the load contacts. Keep the logic wiring short and route high-voltage conductors separately. Maintain at least 3–5 mm spacing between low-voltage traces and mains lines on a board layout to reduce electrical leakage and interference.
Connection Layout for a Microcontroller Board and an Electromechanical Switch Module

Connect the control pin of the microcontroller board to the signal input of the switching module through a digital I/O line, typically D7 or D8 on an ATmega328-based board. Supply the module with 5 V from the board’s power rail and link ground lines together. Without a shared ground reference, the control signal will not trigger the switching mechanism.
The switching unit should contain a driver transistor and a protection diode. The transistor allows the low-current I/O pin (usually limited to ~20 mA) to control the coil, which may draw 60–90 mA. The diode is placed across the coil terminals with reversed polarity so that voltage spikes produced during coil collapse do not reach the microcontroller.
For a minimal wiring layout, three conductors run between the controller board and the switching unit: signal, VCC, and GND. The load device connects separately to the module’s COM and NO contacts. When the control pin outputs HIGH (5 V), the internal coil energizes and the normally-open contact closes, allowing current through the external device.
Choose the correct contact pair before powering the system. Modules typically provide COM, NO, and NC terminals. A lamp that should remain off until a command arrives uses COM + NO. Equipment that must remain powered unless interrupted uses COM + NC. This choice defines how the mechanical switch behaves during idle states or controller resets.
Place a 1 kΩ resistor between the digital pin and the transistor base when building the switching interface from discrete components rather than a ready module. This resistor limits base current and prevents stress on the I/O driver stage. A typical NPN device such as 2N2222 or BC547 handles coil currents for most 5 V switching units.
Power distribution requires attention. The microcontroller board regulator can supply only limited current. If several switching units operate simultaneously, provide an external 5 V supply rated above the combined coil current. Connect its ground to the controller ground so the control signal reference remains stable.
When controlling AC loads such as 120 V lamps or small appliances, route the live conductor through COM and NO while the neutral line goes directly to the load. Maintain clear separation between low-voltage logic wiring and mains conductors; spacing of at least 5 mm on the board prevents accidental bridging and reduces risk during testing.
Testing should proceed with a low-voltage load first, for example a 12 V bulb or DC fan. Upload a simple program that toggles the chosen digital pin every two seconds. A clear clicking sound from the mechanical switch confirms correct wiring, stable power, and proper signal routing between the controller and the switching hardware.