Relay

The relay subsystem exposes a hardware-agnostic on/off view of a single relay, regardless of whether the underlying part is switched by a GPIO line or driven through a PWM channel. A backend driver implements the API and hides all coil-drive details behind it.

Basic Operation

Applications obtain a relay device through devicetree and drive it through the functions in include/zephyr/drivers/relay/relay.h:

Backends

Two devicetree-discoverable backends are provided:

  • zephyr,gpio-relay for a relay switched by a single GPIO. The coil’s active level comes from the flags in the gpios specifier.

  • zephyr,pwm-relay for a relay driven from a PWM channel. The driver owns an optional pull-in/hold current profile: it can drive a stronger pull-in pulse for pull-in-time-ms before dropping to hold-duty-percent to reduce holding current, and periodically re-pulse the coil every refresh-interval-ms. Each stage is opt-in and skipped when set to 0.

Shell

When CONFIG_RELAY_SHELL is enabled, the relay shell command turns relays on and off, reads back their state, and lists the relay devices in the system.

API Reference

Relay