int pirPin = D2;
int switchPin = D0;
int ledPin = D1;
int pirState = LOW;
int buttonState = LOW;
void setup()
{
pinMode( switchPin , INPUT_PULLUP); // sets pin as input
pinMode( pirPin , INPUT );
pinMode ( ledPin, OUTPUT);
Particle.variable ("buttonState", buttonState);
Particle.variable("pirState", pirState);
}
void loop()
{
// find out if the button is pushed
// or not by reading from it.
buttonState = digitalRead( switchPin );
// Using a pulldown resistor we get a LOW
// Signal when its on
pirState = digitalRead( pirPin );
if ( buttonState == HIGH)
{
if ( pirState == HIGH ) // when sensor is on, light turns on
{
digitalWrite( ledPin, HIGH);
}else{
digitalWrite( ledPin, LOW); // when sensor is off, light turns off
}
Particle.publish ("Roommate In", String(buttonState));
delay (500);
Particle.publish ("Roommate activity", String(pirState));
delay (500);
}
}
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. .