Repository navigation
v1.0.0
RelayModule Library
The RelayModule Library is a C++ library providing an abstract interface and implementation for controlling relay modules. It allows users to easily integrate relay functionality into ESP32/Arduino projects, offering methods for turning on/off, toggling, and checking the current state of the relay.
Table of Contents
Introduction
The RelayModule Library simplifies the management of relay modules in ESP32/Arduino projects. It provides an abstract interface for controlling relay states, offering methods for turning on/off, toggling, and checking the current state.
Features
Relay State Control: Abstracts relay control with methods for turning on/off, toggling, and checking the current state.Configurability: Allows users to specify the pin connected to the relay module and whether the relay is turned on by a high or low signal.
Installation
Method 1:
To use the RelayModule library in your PlatformIO project, follow these steps:
-
Open "platformio.ini", a project configuration file located in the root of PlatformIO project.
-
Add the following line to the
lib_depsoption of[env:]section:
ronny-antoon/RelayModule@^1.0.0 -
Build a project, PlatformIO will automatically install dependencies.
Method 2:
To use the RelayModule library in your Arduino project, follow these steps:
-
Download the latest release from the GitHub repository.
-
In the Arduino IDE, click "Sketch" -> "Include Library" -> "Add .ZIP Library" and select the downloaded
.zipfile. -
Make sure to link your project with the necessary ESP-IDF libraries for NVS support.
Usage
- Create an instance of the RelayModule class, specifying the pin connected to the relay module and whether it is turned on by a high or low signal.
#include <RelayModule.hpp>
// Create a RelayModule instance with pin 6 and turned on by a high signal
RelayModule relayModule(6, true);- Control the relay state using the provided methods.
// Turn on the relay module
relayModule.turnOn();
// Turn off the relay module
relayModule.turnOff();
// Toggle the relay module state
relayModule.toggle();
// Check if the relay module is currently on
bool isRelayOn = relayModule.isOn();API
The RelayModule Library provides the following classes and interfaces:
RelayModuleInterface: Abstract interface for relay modules.RelayModule: Implementation of the RelayModuleInterface for relay modules.
Detailed documentation and usage examples can be found in the library source code.
Example
Here's a simple example of how to use the RelayModule library to control a relay module:
#include <RelayModule.hpp>
// Create a RelayModule instance with pin 6 and turned on by a high signal
RelayModule relayModule(6, true);
void setup()
{
// Your setup code goes here
}
void loop()
{
// Turn on the relay module
relayModule.turnOn();
delay(1000);
// Turn off the relay module
relayModule.turnOff();
delay(1000);
// Toggle the relay module state
relayModule.toggle();
delay(1000);
// Check if the relay module is currently on
bool isRelayOn = relayModule.isOn();
// Your main loop code goes here
}For a complete list of methods and parameters, refer to the class documentation in the source code.
License
This library is provided under the MIT License. You are free to use, modify, and distribute it as needed.
Contributions
If you'd like to contribute to the Database Library, please follow these guidelines:
- Fork the repository.
- Make your changes and document them.
- Submit a pull request.
Author
This library was created by Ronny Antoon. You can contact me at [ronny.antoon@gmail.com] for any questions or feedback.
Platformio Registry
https://registry.platformio.org/libraries/ronny-antoon/RelayModule