Problem while adding Sensor

Respected,
i am succesfully connected arduino Uno using serial communication.
now i want to add motion sensor with ardiuno.
but when i select add new sensor and upload sketch my connection gone offline so plz guide me.

can you share the code.

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


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

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

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);
    if (currentState != previousState) {
      Cayenne.virtualWrite(VIRTUAL_CHANNEL 1, currentState);
      previousState = currentState;
    }
        previousMillis = currentMillis;
  }
}

what kind of connection are you using.

1 Like

Serial usb connection

you have to modify the same code you used to connect.

ok i will try it.

1 Like