So I just started using cayenne a few hours ago and have no idea how to progress. I have hooked up an 8way relay board to an arduino uno. I am able to control it using the cayenne website and android app without any faults. But when I add a button and motion sensor the cayenne program stops talking to the arduino board which needs to be reset. I am using virtual pin1 for the motion sensor and digital in 11 for the button.
Coding:
#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_PIN 1
#define RELAY_DIGITAL_PIN 4
#define VIRTUAL_PIN 2
const int motionSensorPin = 10;
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "evohytmhql";
void setup()
{
// set digital pin to output
pinMode(RELAY_DIGITAL_PIN, OUTPUT);
Serial.begin(9600);
Cayenne.begin(token);
}
CAYENNE_IN(VIRTUAL_PIN)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1
// assuming you wire your relay as normally open
if (currentValue == 0) {
digitalWrite(RELAY_DIGITAL_PIN, HIGH);
} else {
digitalWrite(RELAY_DIGITAL_PIN, LOW);
}
}
void loop()
{
Cayenne.run();
checkSensor();
}
int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;
void checkSensor()
{
unsigned long currentMillis = millis();
// Check sensor data every 250 milliseconds
if (currentMillis - previousMillis >= 250) {
// Check the sensor state and send data when it changes.
currentState = digitalRead(motionSensorPin);
if (currentState != previousState) {
Cayenne.virtualWrite(VIRTUAL_PIN, currentState);
previousState = currentState;
}
previousMillis = currentMillis;
}
}
Circuit Image
Note: I can provide a digital representation of the circuit if required
Thanks for any Help
Mark