Relay example

Relay module must be connected to controller module or with sensor module.

Relay has 3 input holes.

Needed libraries:

lib_deps = ITTIoT

The example code below shows if something is connected to the relay module

#include <Arduino.h>
#include <ittiot.h>
 
#define RELAY_PIN 5
 
// If 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 //Peale Serial.begin ja enne iot.setup
  iot.setup();
  pinMode(RELAY_PIN, OUTPUT);
}
 
void loop()
{
  iot.handle();  
  delay(200);
}
en/iot/examples/relay.txt · Last modified: 2018/09/05 15:46 by tomyKalm
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0