Skip to content
Vladimír Záhradník edited this page Aug 17, 2019 · 3 revisions

SimpleRelay provides high-level abstraction over relay control.

Following functions are available:

  • on() will turn relay on
  • off() will turn relay off
  • toggle() which will either turn relay on or off, based on previous state
  • isRelayOn() which will tell, if a relay is currently on.

Initialization

Relay object is initialized with a following command:

SimpleRelay relay = SimpleRelay(OUTPUT_PIN);

Where OUTPUT_PIN represents a GPIO which, which will control the relay.

Optionally, you can also pass a boolean value isInverted to specify relay characteristic. By default this value is set to false.

Non-inverted vs. inverted relay

A relay is non-inverted, when it will turn on after setting voltage on output pin to HIGH. In contrary, inverted relay will turn on when output voltage is set to LOW.

Working with a relay

After a SimpleRelay object is initialized, you can call all of the functions mentioned above.

Clean up

SimpleRelay also defines a destructor, which will set pin back to high impedance input mode. We're mentioning it here for a full reference. In most cases you'll initialize a relay object and use it in your code until your Arduino board is reset.

Clone this wiki locally