Introduction
Today we will show you how to construct a knock lock using a Mindstorms NXT and the Internet of Things platform thethings.iO to monitor it. The programming is done in Matlab.
We use a sound sensor to recognize different knock sequences. If one of the accepted knock sequences is detected the door will be opened. Every attempt to open the door, successful or not, will be sent to thethings.iO. Furthermore, the lock sequences are personalized, so we can monitor from everywhere who opened our door, when it was opened or if there was a false attempt.
We could also program a trigger in thethings.iO, for example, to send us an email
every time that there is a false attempt to open our door.
Here you can see a video to demonstrate how the knock lock works.
Advise: This is not really a secure system ;)Materials
In order to construct the knock lock you need:
- Account from thethings.iO
- A computer with Matlab version 2015a or higher and the NXT Toolbox installed
- Mindstorms NXT brick
- Mindstorms NXT motor
- Mindstorms NXT sound sensor
- 2 cables to connect the sound sensor and the motor
- 1 USB cable to connect the brick to the computer
- Some pieces of Lego to construct a door
Construction
- First, we put the motor and the brick together:
- Then we construct a door:
- And we connect it to the motor:
- Then we build a structure for the sound sensor:
- Then we build a structure for the sound sensor:
- Connect the motor to port A
- Connect the sound sensor to port 2
- Finally, connect the USB cable to the computer
Programming
The code basically consists of a loop that waits until a knock is detected, a function that registers the intervals of the knock sequence, another that compares it with valid sequences, another that sends the results to thethings.iO and another that opens the door.
For further details, on how the code works, look at the comments in the code.
How it works
After executing the code, the program takes a moment to initialize the brick. When it is ready, it says so via console and the brick also emits a sound. Now you can knock.
Knock sequences consist of 5 knocks with 4 intervals. The accepted sequences are:
- Peter: long, long, long, long
- Mary: short, short, short, short
- John: long, short, long, short
The program registers the sequence, compares it and if it is one of the valid sequences it outputs the name to who this particular knock sequence is associated. A nice melody is played and the door is opened for two seconds. After that, there is a pause for 2 seconds before the program is ready for another sequence.
If the sequence is not one of the accepted ones, the brick emits a high pitched tone and the door stays closed. After a pause of two seconds the program is ready for another sequence. If you wait more than 3 seconds between two of the five knocks the program interprets it as a false attempt.
Every time Peter, Mary and John enter the door, this is sent to the thethings.iO so that we can monitor the dates, times and names of the door activity. Furthermore, false attempts are also registered.
Comments