Skip to content
/ Relay Public

A no-frills, easy to use Arduino relay/relais library for shields or modules.

License

Notifications You must be signed in to change notification settings

sekdiy/Relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Relay Library Version 1.1

Purpose

Relay is an Arduino library that provides easy, no-frills access to relays.

Actually, what it does is providing an abstraction from handling digital output port pins yourself. It just so happens that switching a load is a widespread use case. ;)

Simple Example

Using a Relay is really straightforward:

void loop() {
  // flip around
  Lamp.toggle();

  // tell the current state
  Serial.print("The lamp is ");
  Serial.println(Lamp.isOn() ? "on." : "off.");

  // wait a sec
  delay(1000);
}

In the above example, a Relay object Lamp is assumed. This Lamp is toggled every second. Additionally the current state is printed, according to the internal state of the Lamp object.

See the Simple example (included with this library) for the complete code.

Multiple Relays Example

You can of course use multiple relays (connected to their respective pins):

// create a couple of Relay instances
Relay Speaker = Relay(1);
Relay Lamp    = Relay(2);
Relay Heater  = Relay(3);
Relay Fan     = Relay(4);

void setup() {
  // set the mood
  Speaker.on();
}

void loop() {
  // trigger some madness
  Lamp.toggle();

  if (Lamp.isOn()) {
    Heater.toggle();
  } else {
    Fan.setState(Heater.getState());
  }

  // never switch a relay at high rates!
  delay(1000);
}

Relay modules with up to eight channels are very affordable.

Take a look at the RelayModule example for more.

Installation

Download

Just check out the Relay Repository on GitHub (or download the ZIP archive) and copy it to your libraries/ folder (usually within your Arduino sketchbook).

After (re)launching the Arduino IDE, Relay will appear in your Sketchbook/Examples menu.

Arduino Library Manager

Alternatively, you can use Arduino's Add .ZIP Library... menu option.

Please see the libraries guide for further instructions.

Documentation

For further documentation please take a look at the examples and into the source code .

The files Relay.h and Relay.cpp are documented and contain additional clues that may help to understand the functionality.

About

A no-frills, easy to use Arduino relay/relais library for shields or modules.

Resources

License

Stars

Watchers

Forks

Packages

No packages published