Problem while adding Sensor


#1

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.


#2

can you share the code.


#3
#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;
  }
}

#4

what kind of connection are you using.


#5

Serial usb connection


#6

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


#7

ok i will try it.