Skip to main content

Relay - Switching the relay (regular example)

This page contains a simple example with function documentation on how to control the 1 or multi channel regular relay board.

Code example for 1 channel

// Include our CH_Relay library
#include "Relays-SOLDERED.h"

#define RELAY_PIN 5

CH_Relay Relay(RELAY_PIN);

void setup()
{
Relay.begin();
}

void loop()
{
Relay.relayControl(CHANNEL1, HIGH);
delay(1500);

Relay.relayControl(CHANNEL1, LOW);
delay(1500);
}

CH_Relay Relay()

Creates relay object, number of channels depends on how many parameters are given to the constructor (there can be 1,2,4 arguments)

Returns value: NaN

Function parameters:

TypeNameDescription
uint16_tpin1digital pin number for controlling relay on channel 1
uint16_tpin2digital pin number for controlling relay on channel 2
uint16_tpin3digital pin number for controlling relay on channel 3
uint16_tpin4digital pin number for controlling relay on channel 4

Relay.begin()

Initializes relay library

Returns value: none

Relay.relayControl()

Sets specified relay in high or low state

Returns value: none

Function parameters:

TypeNameDescription
uint16_tchannelChannel selection
uint16_tmodeSet relay in HIGH (on) or LOW (off) mode

Full example

Try all of the above mentioned functions in this full example.

RelayControl1CHNative.ino

Example file to show how to control 1 channel relay board.