Device: Arduino Uno with W5100 ethernet shield
Dashboard used: Web and IOS
Description:
I have an Arduino Uno with the Ethernet W5100 shield. I have a breadboard with with a PIR Sensor (#555-28027) and an LED attached. The motion sensor dashboard widget displays data correctly (1 or 0 ). The LED light can be turned on and off using a light widget on the dashboard. When I first added the widgets and create a trigger , the LED light would turn on and off with the motion. After about an hour it stopped without any changes made by myself. I reloaded the code to the Arduino and the triggers still do not work.
Trigger set:
If Arduino - Digital Motion sensor (MotionSensor, Channel 1) = On (1) then Arduino RED LED (DigitalActuator,virtual Pin 5) = On.
If Arduino - Digital Motion sensor (MotionSensor, Channel 1) = On (0) then Arduino RED LED (DigitalActuator,virtual Pin 5) = Off.
Thinking I overloaded the triggers I deleted all triggers and only added back the one that should turn on the LED when motion is detected. I also reloaded the code to the Arduino and the trigger still doesn’t work.
The actual code I am using is pretty simple:
#include <CayenneEthernet.h>
char token[] = "xxxxxx";
// Virtual Pin of the Digital Motion Sensor widget.
#define VIRTUAL_PIN V1
// Digital pin the motion sensor is connected to.
const int motionSensorPin = 2;
void setup()
{
Cayenne.begin(token);
}
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;
}
}