Digital Motion Sensor Not responding after MQTT Switch

I removed the motion sensor and tried another one. No luck. Then I put the old motion sensor back in and “Presto” it started working. This was my first unit and it must have a bad connection somewhere. I was really convinced that I had botch something in my code. I will have the other unit tested with the same code when someone is in that office. - Thanks again Adam!

1 Like

Might be worth changing out your jumper cables. They can get crimped wrong or not have a tight connection inside the plastic piece and that causes the exact problem you were seeing. An easy way to check is with a multimeter in continuity mode. hook up to each end and wiggle the cable a bit. If you hear the beeping stop at any time, replace the cable.

Adam,

Thank you. I will do that on all the connections. My next step is to get all the switches for the lights coded so I can begin the process of setting up all the triggers again. It was set to white light for motion, green for safe temp, yellow for getting too warm and red for send me a text message the server room is burning up. I really like Cayenne’s text message trigger option. Have they ran any updates to the trigger code yet?

Regards,

WW

No trigger updates yet, but it is being worked on. That being said, you may notice that they are not 100% reliable right now so it’s probably not your code if you have issues.

It looks like the Arduino motion sensor is responding and the light is responding but not yet together with the triggers. Any news on this?

Triggers should be working now. Can you post a screen shot of what you have in the settings?

Adam,

Here are the simple triggers for light by motion that I setup:

And

The other strange behavior that I see is when I log into Cayenne it shows all of the light switches on even though they were left off. I turn them off and back on the light will come on for the device.

This is something we will fix in a future update.

As for the triggers, we will monitor that situation. We currently show our triggers working and can’t replicate your specific issue.

1 Like

Thank you for your reply. So you have been able to use the motion sensor to trigger a light switch then? Perhaps there is something else going on with my code. I too will experiment with the triggers further and verify my Arduino scripts.

WW

can yo post your code. triggers are working fine.

The motion sensor responds and the light switch works. It is just when I setup the triggers nothing seems to happen with the light. Here is my script which contains four lights, motion sensor, temp sensor and lux sensor configuration:

/*

This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

1. Set the Cayenne authentication info to match the authentication info from the Dashboard.

2. Compile and upload the sketch.

3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

#include <CayenneMQTTEthernet.h>

#include <OneWire.h>

#include <DallasTemperature.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.

char username[] = "authentication is here";

char password[] = " authentication is here ";

char clientID[] = " authentication is here ";

#define LUXSENSOR_PIN 0

#define TEMPSENSOR_PIN 7

#define MOTIONSENSOR_PIN 2

#define WHITELIGHT_PIN 3

#define GREENLIGHT_PIN 6

#define YELLOWLIGHT_PIN 5

#define REDLIGHT_PIN 4

#define VIRTUAL_CHANNEL1 1

#define VIRTUAL_CHANNEL2 2

#define VIRTUAL_CHANNEL3 3

#define VIRTUAL_CHANNEL4 4

#define VIRTUAL_CHANNEL5 5

#define VIRTUAL_CHANNEL6 6

#define VIRTUAL_CHANNEL7 7

OneWire oneWire(TEMPSENSOR_PIN);

DallasTemperature sensors(&oneWire);

void setup()

{

  Serial.begin(9600);

  Cayenne.begin(username, password, clientID);

  sensors.begin();

  pinMode(WHITELIGHT_PIN, OUTPUT);

  pinMode(GREENLIGHT_PIN, OUTPUT);

  pinMode(YELLOWLIGHT_PIN, OUTPUT);

  pinMode(REDLIGHT_PIN, OUTPUT);

}

void loop()

{

  Cayenne.loop();

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

    if (currentState != previousState) {

      Serial.println("Sending data to Cayenne");

      Cayenne.virtualWrite(VIRTUAL_CHANNEL3, currentState, "digital_sensor", "d");

      previousState = currentState;

    }

        previousMillis = currentMillis;

  }

}

// This function is called at intervals to send sensor data to Cayenne.

CAYENNE_OUT(VIRTUAL_CHANNEL1)

{

  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(LUXSENSOR_PIN));

}

// This function is called at intervals to send sensor data to Cayenne.

CAYENNE_OUT(VIRTUAL_CHANNEL2)

{

  // Send the command to get temperatures.

  sensors.requestTemperatures();

  // This command writes the temperature in Celsius to the Virtual Channel.

  // Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));

  // To send the temperature in Fahrenheit use the corresponding code below.

  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL2, sensors.getTempFByIndex(0));

}

// This function is called when data is sent from Cayenne.

CAYENNE_IN(VIRTUAL_CHANNEL4)

{

  int value = getValue.asInt();

  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL4, WHITELIGHT_PIN, value);

  // Write the value received to the digital pin.

  digitalWrite(WHITELIGHT_PIN, value);

}

// This function is called when data is sent from Cayenne.

CAYENNE_IN(VIRTUAL_CHANNEL5)

{

  int value = getValue.asInt();

  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL5, GREENLIGHT_PIN, value);

  // Write the value received to the digital pin.

  digitalWrite(GREENLIGHT_PIN, value);

}

// This function is called when data is sent from Cayenne.

CAYENNE_IN(VIRTUAL_CHANNEL6)

{

  int value = getValue.asInt();

  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL6, YELLOWLIGHT_PIN, value);

  // Write the value received to the digital pin.

  digitalWrite(YELLOWLIGHT_PIN, value);

}

// This function is called when data is sent from Cayenne.

CAYENNE_IN(VIRTUAL_CHANNEL7)

{

  int value = getValue.asInt();

  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL7, REDLIGHT_PIN, value);

  // Write the value received to the digital pin.

  digitalWrite(REDLIGHT_PIN, value);

}

i think i might have found a bug, let me try it out and will update you later. can you share a screenshot of the dashboard with widgets.

you only have problem with motion sensor, so try the below code . on dashboard go to: add new > devices/widget > custom widget > motion and fill all the details with channel 9 selcted. next add a trigger to this widget. i have test this right now and works fine.

/*
Cayenne Digital Motion Sensor Example

This sketch shows how to send Digital Motion Sensor data to the Cayenne Dashboard.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Attach a Digital Motion Sensor to a digital pin on your Arduino.
   Schematic:
   [Ground] -- [Digital Motion Sensor] -- [5V]
                         |
                     Digital Pin
2. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
3. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a Digital Motion Sensor widget you have added) in the Dashboard.
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
5. Compile and upload this sketch.
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Digital Motion Sensor widget you have added) with data.
   To make a temporary widget permanent click the plus sign on the widget.
*/
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";


#define SENSOR_PIN 26 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 9

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID);
}

void loop()
{
	Cayenne.loop();
	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(SENSOR_PIN);
   Serial.println(currentState);
		if (currentState != previousState) {
			Cayenne.virtualWrite(VIRTUAL_CHANNEL, currentState,"digital_sensor", "d");
			previousState = currentState;
		}
        previousMillis = currentMillis;
	}
}

Thank you so much for looking into it.

WW

Thank you for your input. It was a script error on my part I believe. The line below in red was two lines above your location in mine. It seems to be working now so I can proceed with the rest of the triggers (temp and other lights). You guys are great!

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(SENSOR_PIN);
   Serial.println(currentState);
               if (currentState != previousState) {
                       Cayenne.virtualWrite(VIRTUAL_CHANNEL, currentState,"digital_sensor", "d");
                       previousState = currentState;
               }
        previousMillis = currentMillis;
        }
}

i saw u are using a chinese clone w5100 watch out u have the wrong resistor on the smb 511 (510ohm) should be 510 (50ohm)
if u switch to long network cable dhcp will fail do this ::
So i did as k1ggi did. Soldered 2x 100ohm resistors to pins 1-2 and 3-6. Works perfect with the DHCP address printer example ethernet sketch. I am connected to a Tp-link router, and i am using a arduino Mega, also chinese clone. Thanks!!!
from this thread

I have moved on the setting up the temperature indicator lights with the triggers. The green light is set to trigger ON if below 78 degrees F and another trigger is set to turn OFF the green light if above 78 degrees F. The second trigger does not show it activates.

Is there something in the new system that prevents having a second trigger on the same sensor?

My next step would be to setup ON and OFF triggers for the Yellow and Red lights but I need one working before moving on to the next.

I setup triggers for lights on and off based on the temp. The Arduino Den seems to keep going off line now. I upload the sketch and it comes on line for a few seconds or minutes then goes off again.