Joel D
Published

Doorknob Sensor

A sensor connected to a Particle Photon which sends notifications to your phone when movement detected.

BeginnerFull instructions provided93
Doorknob Sensor

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Tilt Switch Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1

Software apps and online services

NTFY.sh
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Breadboard Wiring

The wires are each connected to a port of the tilt switch. The pins being ground, 3.3v, and Digital Pin 2.

Elegoo Sensor Wire Setup

Code

Doorknob Sensor

C/C++
With the tilt sensor, it gives a signal to the photon which uses a webhook to send a post request to NTFY, alerting my phone.
SYSTEM_MODE(AUTOMATIC);

int tiltPin = D2;

void setup() {
  pinMode(tiltPin, INPUT_PULLUP);
}

void loop() {
  // If tilt switch closes (door opens)
  if (digitalRead(tiltPin) == LOW) {
    if (Particle.connected()) {
      Particle.publish("push-notification", "Door opened", PRIVATE);
    }
    // Wait until the tilt switch is released to avoid spamming
    while (digitalRead(tiltPin) == LOW) {
      delay(100);
    }
  }
  delay(100);
}

Credits

Joel D
1 project • 0 followers

Comments