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:
| Type | Name | Description |
|---|---|---|
uint16_t | pin1 | digital pin number for controlling relay on channel 1 |
uint16_t | pin2 | digital pin number for controlling relay on channel 2 |
uint16_t | pin3 | digital pin number for controlling relay on channel 3 |
uint16_t | pin4 | digital 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:
| Type | Name | Description |
|---|---|---|
uint16_t | channel | Channel selection |
uint16_t | mode | Set 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.