Back to Parent

Code
int ledPin = D0;
int tiltPin = D4;
int tiltReading;
int previous = 0;
String body = "Your housemate has just locked the door!";


void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(tiltPin, INPUT_PULLUP);
  Particle.variable("tiltSensor", tiltReading );
}


void loop()
{
  tiltReading = digitalRead(tiltPin);

  if( tiltReading == 1 )
      {
        // make sure once the sensor is tilted and stays in that position, the notification won't keep sending
        if( tiltReading != previous )
          {
            // turn the LED On
            digitalWrite( ledPin, HIGH);
            // publish an event to Particle console
            Particle.publish( "iveBeenTilted" );
            Particle.publish("twilio_sms", body, PRIVATE);
            previous = tiltReading;
          }

      }else{
       // otherwise
       // turn the LED Off
       digitalWrite( ledPin, LOW);
       previous = tiltReading;

      }
  delay(2000);

}
Click to Expand

Content Rating

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

0