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.
List of Relay features implemented in Shunya stack
With Shunya stack you can make Relay
- Switch On/Off.
Using Relay Shunya stack
Requirements to use Relay Shunya stack
- Shunya OS installed (supported Arm devices) i.e (Raspberry Pi)
- 1x Relay
Steps to use Relay Shunya stack
- Connect Relay to your Arm device i.e (Raspberry Pi) .
- Switch On/Off Relay.
note
Run the steps given below inside Shunya OS installed (supported Arm devices).
Step 1: Connect Relay.
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 :
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-actuatorsOpen the
operate-actuators.c
in an text editor and modify as per your use case.For our example, we need to first get the waterlevel data, add the code in your
main()
functionfloat waterlevel = 76.98; /* For now lets assume that the waterlevel is 76.89 % full*/
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.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 */
}Once you are done editing, save and compile the code , by running
mkdir build && cd build
cmake ../
makeRun the code
sudo ./operate-actuators