Skip to main content

Relay

warning

The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is Relay?

Relay is an electronic switch.

Oops!, No Image to display.

List of Relay features implemented in Shunya stack

With Shunya stack you can make Relay

  1. Switch On/Off.

Using Relay Shunya stack

Requirements to use Relay Shunya stack

  1. Shunya OS installed (supported Arm devices) i.e (Raspberry Pi)
  2. 1x Relay

Steps to use Relay Shunya stack

  1. Connect Relay to your Arm device i.e (Raspberry Pi) .
  2. Switch On/Off Relay.
note

Run the steps given below inside Shunya OS installed (supported Arm devices).

Step 1: Connect Relay.

Oops!, No Image to display.

Step 2: Switch On/Off Relay.

Let's take an example use case: Say we need to

  • Read data from the waterlevel sensor connected to Shunya and,
  • Switch on Relay when the waterlevel is high.

Steps are :

  1. Start with an ready to use template for sending messages via MQTT

    git clone https://gitlab.iotiot.in/repo-public/examples.git
    cd examples/simple-examples/operate-actuators
  2. Open the operate-actuators.c in an text editor and modify as per your use case.

  3. For our example, we need to first get the waterlevel data, add the code in your main() function

    float waterlevel = 76.98; /* For now lets assume that the waterlevel is 76.89 % full*/
  4. Initialize Relay, modify the code

    int relayPin = 36; /*Define Relay pin, Note this should be as per your connection */

    pinMode(relayPin, OUTPUT); /* Initializes LED pin as Output */
    warning

    Relay should be initialized only once in the whole program. Calling pinMode() multiple times will cause error with the library.

  5. To turn on Relay, modify the code

    float temperature = 76.89; /* Assume that the temperature is 76.89 deg C*/

    if (temperature == 70.00f){
    digitalWrite(relayPin, ON); /* Turn on Relay */
    } else {
    digitalWrite(relayPin, OFF); /* Turn off Relay */
    }
  6. Once you are done editing, save and compile the code , by running

    mkdir build && cd build
    cmake ../
    make
  7. Run the code

    sudo ./operate-actuators

Facing errors with the component?