Knok Knok

Made by Hua Fan

Found in Home Hack

The goal of Knok Knok is to be a smart monitor for homes. It will be able to identify when the door is open/closed and send the data to the Internet. When intrusion happens, it will also be able to alarm the user as well as neighbors.

0

Knok Knok

Hua Fan

Proposal

Until now, apartment dwellers have had a difficult time protecting their homes. Unable to permanently install security systems has left their belongings and themselves vulnerable. Knok Knok is a smart home security solution with a goal being to help people monitor their home and notify potential dangers. Knok Knok will be installed on the door and will detect whether there are suspicious activities outside. If there are people wondering outside the door, they will trigger Knok Knok’s alarm and all the data will be registered online.

Parts

CPU: Photon* 1

Sensor: Tilt Sensor * 1

Input: Button * 1

Output: Piezo Buzzer * 1, Red LED * 1, Green LED * 1

Other: 220 ohm Resistor * 1, Wires

Problem Statement

How to secure a home by alarming the trespassers and notifying the residents when someone breaks in?

Goal

This project is designed for people who want to secure their home and can take control of their home security remotely. The user will be able to receive notification for any suspicious behaviours in his/her house. The system will also alarm anyone breaking into the house and scare them away.

Process

Designing the circuit

At the first step, I designed the circuit on Autodesk Tinkercad (see video for process). Since Tinkercad does not have a Photon icon, I used Arduino in the diagram, but the idea is the same. In the diagram, red wires go to 3.3V, green wires go to ground, and other colored wires go to pins. The idea is that the tilt sensor is installed on a door so that when someone breaks into the room, the red LED and the buzzer will go off. The green LED serves as a power indicator. The system can be controlled by a button.

0
Wiring the circuit

I tried my best to keep my circuit simple and clear. See the video for detailed process.

0

Coding the circuits

In the coding step, two more functions were added into the system. First is the online control mechanism. The Wi-Fi connectivity of the Photon enables me to program an online portal for users to view system status and turn it ON/OFF. The online function is called "Knok". User can type "ON" or "OFF" to control the system. The variable "system" indicates the system status (1 for on and 0 for off).

Second, I utilized the IFTTT service so that whenever the alarm even is sent to the cloud, users will receive an email notification so that they do not need to log in to the particle console to view the status.

0
/*
Hua Fan
IoT creative assignment 1
Knok Knok
*/

// variables that won't change
const int powerPin = 0;
const int buttonPin = 1;
const int tiltPin = 2;
const int alarmPin =  3;
const int ledPin = 4;

// variables that will change:
int buttonState = 0;
int tiltState = 0;
int systemOn = 0;
int currentTime = 0;
int peace = 0;

int systemControl(String command);

void setup() {
  // establish serial monitor connection
  Serial.begin(9600);

  // set up all input and output
  pinMode(powerPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(tiltPin, INPUT);
  pinMode(alarmPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  // set up cloud variables and functions
  Particle.function("Knok", systemControl);
  Particle.variable("system", systemOn);
  //Particle.subscribe("Knok Knok", systemControl);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed
  if (buttonState == HIGH) {
    changeSystemStatus();
  }

  // start the system if system is off and button is pressed
  if (systemOn == 1) {
    tiltSensorOn();
    digitalWrite(powerPin, HIGH);
  } else {
    digitalWrite(powerPin, LOW);
  }

  currentTime = millis();
  while(millis() < currentTime + 100){
    //wait 1 second
  }
}

// read sensor data and respond correspondingly
void tiltSensorOn() {
  // read the state of the tilt sensor value:
  tiltState = digitalRead(tiltPin);
  // alarm is tilt sensor give potisive feedback
  if (tiltState == HIGH) {
    playAlarm();
    if (peace == 1) {
      Serial.println("Intruder Detected!!!");
      Particle.publish("Alert", "Intruder Detected!!!", PRIVATE);
    }
    peace = 0;
  } else {
    digitalWrite(ledPin, LOW);
    digitalWrite(alarmPin, LOW);
    if (peace == 0) {
      Serial.println("It's a peaceful day");
      Particle.publish("Status", "It's a peaceful day", PRIVATE);
    }
    peace = 1;
  }
}

// play alarm sound and red LED light
void playAlarm() {
  tone(alarmPin,2800);
  digitalWrite(ledPin, HIGH);
  currentTime = millis();
  while(millis() < currentTime + 100){
    //wait
  }
  digitalWrite(alarmPin, LOW);
  digitalWrite(ledPin, LOW);
}

// change on/off status
void changeSystemStatus() {
  if (systemOn == 0) {
    systemOn = 1;
    digitalWrite(powerPin, HIGH);
    Serial.println();
    Serial.println("System: On");
    Serial.println("Security Check: On");
    Serial.println("Full Protection: On");
    Serial.println();
    Particle.publish("Status", "System: On", PRIVATE);
  } else {
    systemOn = 0;
    digitalWrite(powerPin, LOW);
    Serial.println();
    Serial.println("System: Off");
    Serial.println("Security Check: Off");
    Serial.println("Full Protection: Off");
    Serial.println();
    Particle.publish("Status", "System: Off", PRIVATE);
  }
}

// control the system over the cloud
int systemControl(String command) {
   // find out the state of the system
   if (command == "ON") {
	   systemOn = 1;
     return 1;
   } else if (command == "OFF") {
	   systemOn = 0;
     return 1;
   } else {
     return -1;
   }
}
Click to Expand
0

Outcome

0
Creative Project 1: Home Hack
Hua Fan - https://youtu.be/K6hd-hEHDnQ
0

Reflection

Overall, the project was fun to work on and the result was successful, but there are also some places that can be improved"

What goes well:

  • The circuit works as expected;
  • The remote control function works as expected, so users can turn the system ON/OFF online;
  • The email notification feature works just fine;
  • It was difficult to align the green LED (power indicator) to the system status in the code, but I managed to make sure the LED is turned ON/OFF correctly whether the user is sending messages with the button or online.

What needs improvement:

  • The tile sensor is not super accurate. It has lag or requires extra shake to be triggered sometimes.
  • The system was not installed on an actual door. If given more time, I would further test its usability by putting it on my door.
  • The email notification from IFTTT is slow. It takes 1-2 minutes to receive the email. Also, the code does not prevent sending multiple emails at the same time. To avoid getting spammed, the code would work better if I include a mechanism to send one email at a time.
  • The button is too close to the sensor. In real life scenarios, the sensor should be far away from the button, as least on the inside of the door.
x
Share this Project

Found In
Courses

49-713 Designing for the Internet of Things

· 26 members

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


Focused on
About

The goal of Knok Knok is to be a smart monitor for homes. It will be able to identify when the door is open/closed and send the data to the Internet. When intrusion happens, it will also be able to alarm the user as well as neighbors.

Created

January 23rd, 2018