//FINAL CODE WITH IFFTTT INTEGRATION
int hallPin = A0;
int redPin = D0;
int greenPin = D1;
int pastState = 1;
int currentState = 1; // 1 = Green, 0 = Red
void setup(){
pinMode( redPin, OUTPUT);
pinMode( greenPin, OUTPUT);
pinMode (hallPin, INPUT);
}
void loop(){
int hallState = digitalRead( hallPin ); // to store and read state of hall effect sensor
if( hallState == LOW ) // LOW = vacant, HIGH = occupied
{
digitalWrite( redPin, LOW);
digitalWrite(greenPin, HIGH); // green when vacant
currentState = 1;
if( currentState != pastState){
Particle.publish("occupied"); // publish event to particle cloud
pastState = currentState;
}
}else{
digitalWrite( greenPin, LOW);
digitalWrite(redPin, HIGH); // red when occupied
currentState = 0;
if( currentState != pastState){
Particle.publish("vacant"); //publish event to particle cloud
pastState = currentState;
}
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .