Doorknob Sensor

Made by Jon Sharrah

A simple build that gives you a log of every time that silly door knob has been turned! Comes with a light and a button.

Created: January 28th, 2016

0

Problem Statement

I designed this device for my girlfriend, who has a life long fear of home invaders. I figured that if she had some reliable way to know immediately and precisely when the doorknob has been turned, she might feel a bit safer when home alone.


Goal

In this project, I set out to create a device that could be affixed to a doorknob. When the doorknob is twisted, the device will indicate locally using an LED (to verify proper function), and send an alert to the cloud, logging the time which the event occurred. There will also be a switch to manually disable the device when a user is home.


Process

2 - 220Ω resistors

1 - 1kΩ resistor

1 - 10kΩ resistor

1 - Latching button switch

1 - Red LED

1 - Tilt Ball #173 sensor

1 - Particle Photon

various Jumper Wires


0

A bit more organized for clarity:

0

The code is a substantially modified version of a SparkFun repository, which they provide on the order page for the tilt sensor.  I had to reverse engineer the wiring for the sensor from the frustratingly short video on that order page.  After I had it operational, the next challenge was to integrate some variables for debugging, and add a publish function so that the alerts would be logged and viewable remotely.  This was accomplished using experience from our class tutorials.  The final step was to wire up a kill switch, so that the alerts could be disabled while at home.  After some digging in the lab, I found one latching button.  About a dozen configurations later, Steffen helped me solve the floating voltage issues and I had a solid on/off signal.  A few more lines of code to define the status of the switch (and add it to the IF statements) and the device was fully operational.

0
const int ledPin = D0;
const int tiltSensor = A0;
const int switchpin = D2;


int sensorReading;      // variable to store the value read from the sensor pin
int ledState = LOW;       // variable used to store the last LED status, to toggle the light
int tiltState;            // the current reading from the input pin
int lastTiltState = HIGH; // the previous reading from the input pin
int switchstatus;

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(tiltSensor, INPUT);

 Spark.variable("door", &sensorReading, INT);
 Spark.variable("switch", &switchstatus, INT);

}

void loop() {
  sensorReading = digitalRead(tiltSensor);
  switchstatus = digitalRead(switchpin);

  if (sensorReading != lastTiltState) {
    lastDebounceTime = millis();
  }
   if ((millis() - lastDebounceTime) > debounceDelay) {

    if (sensorReading != tiltState){
      tiltState = sensorReading;

      if (sensorReading == LOW & switchstatus == HIGH) {
        ledState = HIGH;
        digitalWrite(ledPin, ledState);
        delay(500);
        Spark.publish("Door","opened!",60,PRIVATE);
      }

      else if (sensorReading == HIGH){
        ledState = LOW;
        digitalWrite(ledPin, ledState);
      }
    }
   }
  lastTiltState = sensorReading;
  delay(100);
}
Click to Expand
0

Outcome

The final product works as intended, though admittedly the package is a bit unwieldily.  It can easily be attached to a doorknob using rubber bands or adhesive, but the bulky breadboard prevents easy operation of the knob itself.  The power source (USB cable or battery pack) doesn't help either.  It really requires a more elegant enclosure.

While encasing the device is a longer-term goal, a more immediate improvement would be the addition of better notification services.  The cloud logs are nice, but SMS alerts would be much more noticeable.  One more thing to look at is idle power consumption.  Ideally, the circuit should be extremely lean, and I have not tested this aspect of performance yet.


Reflection

This project was highly informative for me, and a great hands-on learning experience.  I work closely with several electronics engineers on a daily basis, and I am consistently baffled by the complexity of their work.  Building this device gives me an even greater respect for what they can do.  That said, I felt that I achieved the goal I set out to reach (even if I did receive considerable assistance), and now feel inspired to continue developing more advanced devices.  I'll be pressing on with a new, but appropriately restrained sense of optimism.

x
Share this Project

Courses

49-713 Designing for the Internet of Things

· 4 members

This course charts the emergence of the now "connected world" to explore the possibilities for future products and connected spaces.


Focused on
About

A simple build that gives you a log of every time that silly door knob has been turned! Comes with a light and a button.