Relay - Switching the relay (Qwiic example)
This page contains a simple example with function documentation on how to control the 1 channel relay board using Qwiic conncetion.
Code example for 1 channel
// Include our CH_Relay library
#include "Relays-SOLDERED.h"
#define RELAY_ADDRESS 0x32
CH_Relay Relay;
void setup()
{
Relay.begin(RELAY_ADDRESS); // Set address on relay hardware switch using provided addresses and here (0x30 - 0x37)
// If there are more sensors/breakout boards are connected with same address,
// it is needed to change address in order to have normal I2C communication.
// Every end device should have unique address on same bus
}
void loop()
{
// Turn on relay
Relay.relayControl(CHANNEL1, HIGH);
delay(1500);
// Turn off relay
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: none
Relay.begin()
Initializes relay object for I2C communication
Returns value: none
Function parameters:
| Type | Name | Description |
|---|---|---|
uint16_t | relay_adderss | Board address for I2C communicaion |
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.
RelayControl1CHEasyC.ino
Example file to show how to control 1 channel relay board using Qwiic comunication.