Table of Contents

ITT Relay module

This laboratory is located in the office of ITT Group in Tallinn, Estonia.

Introduction

This laboratory can be used to practice controlling the relay module attached to the controller.

Prerequisites

For this laboratory, the student should understand basic MQTT concepts like topics, broker, subscribing and publishing. Also the basics of relays and where they can be used.

Technical details

This laboratory consists of a relay module attached to the ITT IoT controller module. The relay module is an electrically operated switch of the mains voltage. It means that it can be turned on or off, letting the current go through or not. Many relays use an electromagnet to mechanically operate the switch and provide electrical isolation between two circuits.

Sensors

This laboratory does not have any sensors.

Specifications

Electrical connection

The signal lead of the servo is connected to GPIO5 pin of the controller.

Software, libraries and externals

Communication

The user can connect and program this controller using the Distancelab environment.

Limits

At the same time, only one user can program the controller. But all users connected to the Distancelab MQTT broker can subscribe and publish to topics specified.

Hands-on labs

Example code

#include <Arduino.h>
#include <ittiot.h>
 
#define RELAY_PIN 5
 
// If the message received switch relay
void iot_received(String topic, String msg)
{
  Serial.print("MSG FROM USER callback, topic: ");
  Serial.print(topic);
  Serial.print(" payload: ");
  Serial.println(msg);
  if(msg == "1")
  {
    digitalWrite(RELAY_PIN, HIGH);
  }
 
  if(msg == "0")
  {
    digitalWrite(RELAY_PIN, LOW);
  }
}
 
void iot_connected()
{
  Serial.println("MQTT connected callback");
  iot.subscribe("relay");
  iot.log("IoT relay example!");
}
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Booting");
 
  iot.printConfig(); // print json config to serial
  iot.setup();
  pinMode(RELAY_PIN, OUTPUT);
}
 
void loop()
{
  iot.handle();  
  delay(200);
}

Support

info@ittgroup.ee