Benny Estes
Published © LGPL

Secure Your Home with Arduino And Cayenne

In present time, security is important in the home, office and many other places. In our absence, these places are not secure.

BeginnerShowcase (no instructions)3 hours849
Secure Your Home with Arduino And Cayenne

Things used in this project

Software apps and online services

Cayenne
myDevices Cayenne

Story

Read more

Code

Code snippet #5

Plain text
         #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
         #include <CayenneEthernet.h>

        // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
        char token[] = "AuthenticationToken";

         // Virtual Pin of the Digital Motion Sensor widget.
        #define VIRTUAL_PIN V1

       const int motionSensorPin = 4;

       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 = digitalRead(motionSensorPin);
	if (currentState != previousState) {
		Cayenne.virtualWrite(VIRTUAL_PIN, currentState);
		previousState = currentState;
	           }
          }
        }

Code snippet #6

Plain text
         #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
         #include <CayenneEthernet.h>

        // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
        char token[] = "AuthenticationToken";

         // Virtual Pin of the Digital Motion Sensor widget.
        #define VIRTUAL_PIN V1

       const int motionSensorPin = 4;

       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 = digitalRead(motionSensorPin);
	if (currentState != previousState) {
		Cayenne.virtualWrite(VIRTUAL_PIN, currentState);
		previousState = currentState;
	           }
          }
        }

Credits

guru8196

Posted by Benny Estes

Comments