#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 // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "xph6x521ur"; // Virtual Pin of the Smoke Sensor widget. #define VIRTUAL_PIN V1 // Analog pin the Smoke Sensor is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial. const int smokeSensorPin = A0; void setup() { Serial.begin(9600); 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 = analogRead(smokeSensorPin); Cayenne.virtualWrite(VIRTUAL_PIN, currentState); previousMillis = currentMillis; } }