VinothKumar
Published © LGPL

Home Control With Cayenne

This Project is used to Make our home secure and reduce theft with the help of Motion sensor and Cayenne App.

IntermediateProtip2 hours4,391
Home Control With Cayenne

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Buzzer
Buzzer
×1
9V battery (generic)
9V battery (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Cayenne
myDevices Cayenne

Story

Read more

Code

Home Control With Cayenne

C/C++
#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

// Digital pin the motion sensor is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
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

VinothKumar

VinothKumar

6 projects • 13 followers

Comments