Relay Toggle Sample

This application demonstrates the basic operation of the relay. It uses Arduino IDE's Serial Monitor to display current relay state.

To run the example:

  1. Open the IoT_Node_SSRelay_Toggle sketch from the examples menu.

  2. Select Turta IoT Node from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

#include <Turta_SSRelay_Module.h>

// Create SS Relay instance.
Turta_SSRelay_Module ssr;

void setup() {
  // Initialize SS Relay.
  ssr.begin();

  // Configure serial port.
  Serial.begin(115200);
  delay(200);
}

void loop() {
  // Read relay state.
  bool relayState = ssr.readRelay();

  // Toggle relay.
  ssr.writeRelay(!relayState);

  // Write relay state to serial monitor.
  Serial.print("Relay State: ");
  Serial.println(ssr.readRelay() ? "On." : "Off.");
  
  // Delay 10.000ms = 10 seconds.
  delay(10000);
}

Result

After the application is uploaded to the device, it toggles the relay output every 10 seconds. The application writes current relay state to the Serial Monitor. The LED on the SS Relay Module is lit if the relay is on. The example output should be like this:

Relay State: On.
Relay State: Off.

The application runs forever until you clear it from memory.

Last updated