Back to Parent

int pirPin = D2;
int buttonPin = D0;
int ledPin = D1;
int pirState = LOW;
int buttonState = LOW;

void setup()
{
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(pirPin, INPUT);
  pinMode (ledPin, OUTPUT);
  Particle.variable ("buttonState", buttonState);
  Particle.variable("pirState", pirState);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  pirState = digitalRead(pirPin);
  if (buttonState == LOW)
  {
  if (pirState == HIGH) //button pressed and movement recognized = light on
    digitalWrite(ledPin, HIGH);
  }else{
    digitalWrite(ledPin, LOW);
  }

Particle.publish ("Mowgli inside", String(buttonState));
delay (1000);
Particle.publish ("Mowgli is Drinking", String(pirState));
delay (1000);

}
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0