Arduino Uno w/ PIR motion sensor has triggers that no longer work


Device: Arduino Uno with W5100 ethernet shield
Dashboard used: Web and IOS


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()

void loop()

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;


Hi @davidR,

Welcome to the Cayenne community! Glad you’re here.

@jburhenn any thoughts here as to why the triggers appear to be failing based on his code?



Hi @davidR
you use 250 like millisecond. The value correct is 2500 or 2 seconds and half.
previous state is a boolean value and not int value. Use Try and False for values.


okay. FYI that code was generated by Cayenne not myself :slight_smile
right now it seems to be working and I did not change anything!


I’m not sure why the triggers would not have worked. If it’s working now I suspect it was a temporary issue on the server side.

250 milliseconds should be fine for checking the motion sensor state, but you can increase it if you only need to check for motion sensor changes at longer intervals.


I increased the time to 5000ms just to go easy on the triggers haha. Thanks everyone. I will report in the morning if the triggers are still functioning.


Still working after a few days.