ahmad76
Published © GPL3+

Home Devices Control System With Cayenne

This project used to control home devices through internet using Cayenne IOT server.

IntermediateProtip1 hour1,466
Home Devices Control System With Cayenne

Things used in this project

Story

Read more

Schematics

projets

Code

code.ino

C/C++
code for arduino
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

#define VIRTUAL_PIN1 1
#define VIRTUAL_PIN2 2
#define RELAY_DIGITAL_PIN1 4
#define RELAY_DIGITAL_PIN2 5
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "kcqd0oywxa";

void setup()
{
  // set digital pin to output
  pinMode(RELAY_DIGITAL_PIN1, OUTPUT);
  pinMode(RELAY_DIGITAL_PIN2, OUTPUT);

  Serial.begin(9600);
  Cayenne.begin(token);
}

CAYENNE_IN(VIRTUAL_PIN1)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 1) {
    digitalWrite(RELAY_DIGITAL_PIN1, HIGH);
  } else {
    digitalWrite(RELAY_DIGITAL_PIN1, LOW);
  }
}
CAYENNE_IN(VIRTUAL_PIN2)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 1) {
    digitalWrite(RELAY_DIGITAL_PIN2, HIGH);
  } else {
    digitalWrite(RELAY_DIGITAL_PIN2, LOW);
  }
}

void loop()
{
  Cayenne.run();
}

Credits

ahmad76

ahmad76

2 projects • 1 follower
I

Comments