Skip to main content

Meadow.Foundation.Relays.Relay

Relay
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation

A relay is an electrically operated or electromechanical switch composed of an electromagnet, an armature, a spring and a set of electrical contacts. The electromagnetic switch is operated by a small electric current that turns a larger current on or off by either releasing or retracting the armature contact, thereby cutting or completing the circuit. Relays are necessary when there must be electrical isolation between controlled and control circuits, or when multiple circuits need to be controlled by a single signal.

Sample projects available on GitHub

Code Example

protected Relay relay;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

relay = new Relay(Device.CreateDigitalOutputPort(Device.Pins.D02));

return Task.CompletedTask;
}

public override Task Run()
{
var state = false;

while (true)
{
state = !state;

Resolver.Log.Info($"- State: {state}");
relay.IsOn = state;

Thread.Sleep(500);
}
}

Sample project(s) available on GitHub

Wiring Example

Class Relay

Electrical switch (usually mechanical) that switches on an isolated circuit.

Assembly: Meadow.Foundation.dll
View Source
Declaration
public class Relay : IRelay

Implements:
Meadow.Peripherals.Relays.IRelay

Properties

DigitalOut

Returns digital output port

View Source
Declaration
protected IDigitalOutputPort DigitalOut { get; set; }

Type

Returns type of relay.

View Source
Declaration
public RelayType Type { get; protected set; }

State

Whether or not the relay is on. Setting this property will turn it on or off.

View Source
Declaration
public RelayState State { get; set; }

Methods

Toggle()

Toggles the relay on or off.

View Source
Declaration
public void Toggle()

Events

OnChanged

Event raised after relay state change

View Source
Declaration
public event EventHandler<RelayState> OnChanged
Event Type

System.EventHandler<Meadow.Peripherals.Relays.RelayState>

Implements

  • Meadow.Peripherals.Relays.IRelay