Characteristic Locus
Inheritance System.Object > Relay
Namespace Meadow.Foundation.Relays
Assembly Meadow.Foundation.dll

Syntax

public class Relay : IRelay

Remarks

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.

Examples

The following code illustrates explicitly turning a relay on or off, as well as toggling it’s on state.

using System;
using System.Threading;
using Meadow;
using Meadow.Foundation.Relays;

namespace Relay
{
    public class Program
    {
        public static void Main()
        {
            var relay = new Relay(Device.Pins.D08);

            while (true)
            {
                Debug.Print("turning on");
                relay.IsOn = true;

                Thread.Sleep(500);

                Debug.Print("toggling to off");
                relay.Toggle();

                Thread.Sleep(250);

                Debug.Print("Toggling to on.");
                relay.Toggle();

                Thread.Sleep(250);

                Debug.Print("Turning off");
                relay.IsOn = false;

                Thread.Sleep(500);
            }
        }
    }
}
Example Circuit

Constructors

View Source

Relay(IDigitalOutputPort, RelayType)

Creates a new Relay on an IDigitalOutputPort. Allows you to use any peripheral that exposes ports that conform to the IDigitalOutputPort, such as the MCP23008.

Declaration
public Relay(IDigitalOutputPort port, RelayType type = null)

Parameters

Type Name Description
IDigitalOutputPort port
RelayType type
View Source

Relay(IIODevice, IPin, RelayType)

Creates a new Relay on an IDigitalOutputPort.

Declaration
public Relay(IIODevice device, IPin pin, RelayType type = null)

Parameters

Type Name Description
IIODevice device
IPin pin
RelayType type

Fields

View Source

_isOn

Declaration
protected bool _isOn

Field Value

Type Description
System.Boolean
View Source

_onValue

Declaration
protected bool _onValue

Field Value

Type Description
System.Boolean

Properties

View Source

DigitalOut

Returns digital output port

Declaration
public IDigitalOutputPort DigitalOut { get; protected set; }

Property Value

Type Description
IDigitalOutputPort
View Source

IsOn

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

Declaration
public bool IsOn { get; set; }

Property Value

Type Description
System.Boolean
View Source

Type

Returns type of relay.

Declaration
public RelayType Type { get; protected set; }

Property Value

Type Description
RelayType

Methods

View Source

Toggle()

Toggles the relay on or off.

Declaration
public void Toggle()