Don't Lock Me Out

Made by Mengyang Hong

Found in DIoT 2018 1- Home Hack

A device that can prevent my housemates from being accidentally locked outside when they return late during midnight.

IoT Diagram
Doorlock iot diagram


A frustrating experience I have identified for my housemates (and myself) is that sometimes we stayed at the school library/studio or hung out with friends until late in the midnight and forgot to tell others in advance, which sometimes resulted in one of us got accidentally locked outside when we went back. (We have the habit of locking the house gate from the inner side using a knob before going to bed for safety concerns, in which way the door could not be opened with a key from outside.) 

To solve this problem, I plan to develop an IoT device that can send a text message notification to everyone once someone locks the gate from the inner side, therefore we can react to it quickly.  To realize this function, I plan to put a tilt sensor on the lock (knob) and connect it to a Photon. The Phonton will then integrate with Twilio API to text messages.

Working Prototype


The making process of this project can be divided into 3 steps: 

1. Design a simple circuit that contains an LED as a status indicator, a tilt sensor as an input for triggering events, and a resistor to protect electric components. 

2. Develop code on Particle IDE for controlling the circuit to work as we intended:

- Turn on the LED light when the tilt sensor is tilted, and turn off the LED light when the sensor goes back to the default vertical position.    

- Make sure the tilt sensor functions properly.

- Enable a cloud variable (the status of the tilt sensor) to be inspected.

- Add proper delay to avoid the loop going overwhelmingly frequent.

3.  Integrate Twilio API by adding a webhook on Particle console. Add lines of code to enable Photon to publish events and get responses from Twilio properly. Finally, ensure that messages should be sent to the user under the correct condition.

Circuit Diagram
Doorlock circuit diagram
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;

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


Click to Expand
Particle Console Event Page
Particle console


  • Particle Photon x 1
  • Breadboard x 1
  • Tilt Sensor x 1
  • LED x 1
  • 1kΩ Resistor x 1
  • Jumper Wires 


  • Twilio API
Share this Project


49713 Designing for the Internet of Things

· 25 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.

Focused on

A device that can prevent my housemates from being accidentally locked outside when they return late during midnight.


January 25th, 2018