int pirPin = D1; // motion sensor
int switchPin = D2; // switch that turn on the device
String body = "Hey, someone is in the bathroom"; //text content that will be sent to user's phone
void setup()
{
pinMode (switchPin, INPUT_PULLUP);
// Switch is an input
pinMode (pirPin, INPUT);
// When someone is in the bathroom, the motion sensor will detect it, which is the input.
}
void loop()
{
int buttonState = digitalRead( switchPin );
if (buttonState == LOW)
{
int pirState = digitalRead( pirPin );
// Name the input of pir as pirState
if ( pirState == HIGH ) // When someone enters
{
Particle.publish("twilio_sms", body, PRIVATE);
delay(600000);
// A text massage will be sent to the subscriber's phone every 10 mintutes when there is someone
// and it will stop after the person leaves.
}else{
Particle.publish("twilio_sms", "Nobody is in the bathroom now.", PRIVATE);
delay(600000);
// A text massage will be sent to the subscriber's phone every 8 hours when there is no one
// and it will stop after a person enters.
}
}
}
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. .