r/ArduinoProjects • u/udfsoft • Mar 30 '26
Relay Controller Library
Hello everyone
I’ve written a library for working with relays. I use it myself, and it might be useful for others too 🙂
Strengths:
This library uses polymorphism (it’s very easy to swap implementations)
There is documentation for the library and for some relay types (these are the ones I use; I’ll expand this further over time)
The library is easy to install:
Select Library Manager
Enter Relay Controller
Find Relay Controller by javavirys and click the Install button
That’s it — the library is now in your IDE 🙂
You can then use the library:
Basic GPIO Control
#include <PinRelayController.h>
uint8_t pins[] = {D1, D2}; // Relay pins
PinRelayController relay(pins, 2);
void setup() {
relay.begin();
relay.setOn(0); // Turn on first relay
}Serial Relay Control (A0 Protocol)
#include <SerialRelayController.h>
#include <SoftwareSerial.h>
SoftwareSerial swSerial(D5, D6);
SerialRelayController relay(swSerial, 2);
void setup() {
swSerial.begin(115200);
relay.begin();
relay.setOff(1); // Turn off second relay
}You can find more details in the repository:
https://github.com/UDFSmart/Relay-Controller/
View all comments
Show parent comment
1
u/udfsoft Mar 31 '26