NodeMCU and Digital Motion Sensor

Ok, I think I see what the issue might be here. That example digital motion sensor sketch was written for the Arduino connectivity rather than the MQTT connectivity. However, 95% of it should still be good. We just need to change the virtualWrite() statement so it’s not trying to write to a virtual pin (a concept that doesn’t exist with the MQTT connectivity) and instead to an MQTT channel with appropriate tagging for the data type.

Assuming you still want to write to channel 1, I would switch out the Arduino write statement:

Cayenne.virtualWrite(VIRTUAL_PIN, currentState);

for this MQTT write statement:

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

Delete the existing channel 1 widget before uploading this code change. Once it connects, it should auto-create a new widget on your dashboard (which should actually default to a 2-state type). You then should see settings on this widget to set it to other widget types, one of which is literally a motion sensor widget we have that looks like this:

1 Like