This device has no voice for this language. You can add one in your device’s speech settings.
From a Small Signal to Switching Real Equipment
A home automation controller makes decisions, but at some point those decisions must switch something real: a light, a pump, a heater or a valve. This happens through outputs.
A microcontroller pin can only provide a tiny signal – a few volts and a few milliamps. To switch larger loads, the signal must control something stronger: a transistor, a relay, a solid-state relay or a contactor.
This guide explains how digital outputs work, how to choose the right switching device and how to do it safely.
1. What Is a Digital Output?
A digital output has two states: on (high, for example 3.3 V) and off (low, 0 V). On a microcontroller such as the ESP32, any general-purpose pin can usually be used as an output.
The current a pin can deliver is small – typically a few milliamps up to a few tens of milliamps, depending on the chip. That is enough for a small indicator LED or to control another component, but not to power a load directly.
2. Transistors and MOSFETs
For low-voltage DC loads – LED strips, small fans, buzzers, solenoid valves – a transistor or MOSFET acts as an electronic switch controlled by the pin.
- Choose a logic-level MOSFET that switches fully on at 3.3 V for loads such as 12 V LED strips.
- Connect a resistor between the gate and ground, so that the output stays off while the microcontroller is starting.
- For motors, solenoids and relay coils, add a flyback diode across the load. It protects the transistor from the voltage spike created when the coil is switched off.
- Make sure the power supply, wires and MOSFET are rated for the current of the load.
3. How a Relay Works
A relay is an electrically operated switch. A small current through a coil creates a magnetic field that moves a contact. The contact can switch a completely separate circuit – often at a much higher voltage and current.
Relay contacts are described as:
- NO (normally open) – the circuit is open when the coil has no power and closes when the relay is activated.
- NC (normally closed) – the circuit is closed when the coil has no power and opens when the relay is activated.
- COM (common) – the shared connection between NO and NC.
The choice between NO and NC decides what happens when the controller loses power – an important part of fail-safe design (see Guide 28).
4. Relay Modules
Ready-made relay modules contain the relay, a transistor to drive the coil, a protective diode and often an indicator LED. Some also have optocouplers that separate the control side from the relay side.
- Check whether the module works with a 3.3 V control signal – many are designed for 5 V.
- Note whether the module switches on with a high or a low signal ("active-high" or "active-low"). An active-low module switches on when the pin is at 0 V, which can cause it to switch on briefly during start-up.
- Check the module’s supply voltage for the coil, usually 5 V or 12 V.
- Inexpensive modules are often not suitable for continuous switching of mains loads near their maximum rating. Treat the printed rating with caution.
5. Contact Ratings and Types of Load
Every relay has a maximum voltage and current for its contacts, often different for AC and DC. The type of load matters as much as its size:
| Load Type | Examples | What to Consider |
|---|---|---|
| Resistive | Heaters, incandescent lamps | Simplest to switch; the rating applies directly |
| Inductive | Motors, pumps, transformers, contactor coils | Sparks when switching off; choose a higher rating and suitable suppression |
| Capacitive and LED drivers | LED lamps, power supplies | High inrush current at switch-on can damage contacts |
| DC loads | Batteries, solar circuits, 12 V and 24 V equipment | DC arcs are harder to break; DC ratings are often much lower than AC ratings |
Leave a generous margin between the actual load and the relay’s rating, especially for loads that run for long periods.
6. Solid-State Relays and Contactors
Solid-state relays (SSRs) switch with semiconductors instead of moving contacts. They are silent, switch quickly and do not wear out mechanically, which suits heating elements that are switched often. However, they become warm under load and may need a heat sink, they often let a small current through even when off, and many types only work with AC.
Contactors are heavy-duty relays mounted in the distribution board. They are used for water heaters, heating cables and other large loads. A small relay or the controller then only switches the contactor’s coil. Installation in the distribution board must be done by a qualified electrician where regulations require it.
7. PWM – Dimming and Speed Control
Pulse-width modulation (PWM) switches an output on and off very quickly. The share of time it is on – the duty cycle – controls the average power. PWM is used to dim LED strips and to control the speed of some DC fans.
PWM requires a MOSFET or driver that can switch fast; ordinary mechanical relays cannot be used for PWM. Mains lighting is dimmed with a suitable dimmer, not with PWM from a microcontroller.
8. Start-Up Behaviour and Safe States
When a microcontroller starts or restarts, its pins can float or briefly change state before the program takes control. This can make a relay click or a pump start for a moment.
- Use pins that are stable during start-up for important outputs.
- Use pull-down or pull-up resistors to hold outputs in a known state.
- Decide in the firmware what state each output should have after a restart.
- For critical equipment, choose the relay contact (NO or NC) so that loss of power leads to the safe state.
9. Electrical Safety
Switching mains voltage is dangerous if it is not done correctly:
- Keep low-voltage electronics and mains wiring physically separated, with sufficient distance on boards and in enclosures.
- Use enclosures that cannot be opened without tools, with proper strain relief for cables.
- Use wire sizes and fuses suitable for the load.
- Never work on circuits while they are connected to the mains.
- Follow the regulations where you live – in many countries, fixed mains installations must be carried out or approved by a qualified electrician.
If you are unsure, use certified ready-made products – such as approved relay modules for wall boxes or DIN rails – and control them from your own electronics with low-voltage signals.
Final Thoughts
Digital outputs turn decisions into actions. Small loads can be switched with transistors and MOSFETs, while relays, solid-state relays and contactors switch larger and mains-powered equipment.
Choose the switching device according to the voltage, current and type of load, leave a generous safety margin and plan what happens at start-up and when power is lost.
Above all, treat mains voltage with respect: separate it from your electronics, enclose it properly and involve a qualified electrician where required.
MISOLIMA® – Technology Made Practical.
Practical knowledge for understanding, designing and building home automation.
Continue reading
Back to the topGuide 26