Introduction: Automated & Secured Front Door
As students in engineering, we have been asked
to carry out a full project including an Arduino and a Raspberry pi.
The idea was to make something useful and that we are interested in. After few conversations with the members of the team, the idea of the secured and automated door came out. We wanted to solve a daily problem. Indeed, who has ever wondered if he correctly locked his front door?
We are here going to try to help you rebuild this project for your own use. Note that with the time constrain and the bugs we had to face, this project is not fully completed as we expected even if most functions are operational. Anyway, every project can be pushed further, improved and enhanced.
The aim of this project is to combine the following functions:
- An alarm system that sound when the door is open, the system is waiting for the deactivation code during 30s and sound with a louder ring if the right code is not type on time.
- A people counter to know how many people are inside and which automatically arm the alarm if nobody is inside while the door is locked.
- An application on an android phone to check the counter, the locking of the door and also allow to lock the door and to arm the alarm remotely.
Step 1: Step 1 - Main Components
let’s talk about the main components of our project and more especially the electronic parts. To achieve the project, two electronic components are mandatory: an Arduino Uno and a Raspberry PI 3.
- Raspberry PI 3:
This component is used to receive information from a mobile application and send information to the Arduino. It also receives the states of the sensors from the Arduino to run correctly the main program of the project.
You can find the link to buy the Raspberry here: https://www.amazon.fr/Raspberry-Pi-3-Model-B/dp/B...
Note that you will also need a 16 GB microSD card and a 5V power supply with this device. You can find this power supply on Amazon: https://www.amazon.fr/Aukru%C2%AE-Alimentation-Ch....
- Arduino Uno:
The Arduino is used to read information from sensors and to control a DC motor. Those data are communicated to the Raspberry device thanks to a Serial Connection.
This is the link to buy an Arduino Uno: https://www.amazon.fr/gp/product/B01AXOEIL4/ref=p...
The power supply of this part is ensured thanks to the serial connection between the Raspberry and the Arduino. You can find one her: https://www.amazon.fr/Seeedstudio-Cable-Arduino-D...
Step 2: Step 2 - Sensors
several sensors are needed. To achieve the model, four kinds of sensors have been used:
- 2 infrared sensors to realise the People Counter Application of our project. Those will notice when a people enter or leave the home.
Link to buy an infrared sensor: https://www.sick.com/fr/fr/product-portfolio/dist...
- 2 contact sensors to check if the door is locked or not.
The link to buy them is: http://www.robotshop.com/eu/fr/capteur-contact-co...
- 1 magnetic sensor to check if the door is opened or not. Those sensors will be used for our made-by-ourselves alarm system.
Here is the link to buy a magnetic sensor: https://www.amazon.com/Magnetic-Sensor-Window-War...
- 1 pushbutton switch to turn on the alarm system manually.
The link to buy one is here: https://www.amazon.fr/Interrupteur-bouton-poussoi...
Step 3: Step 3 - Actuators
the model wouldn’t run without actuators. Two kinds of actuators are used: an electric motor and three coloured LED lights.
- Electric motor :
An electric motor is needed to lock the front door remotely. This one is controlled thanks to the Arduino when the customer activates a button on his mobile application.
To realise the automated locking system, a unipolar stepper motor 28BYJ-48 is chosen. It’s a 5VDC motor often used with Arduino board. The motor is connected to the Arduino device thanks to an ULN2003 driver.
Where to buy those devices: http://tiptopboards.com/151-moteur-pas-%C3%A0-pas...
- LED lights :
Even if those parts are not mandatory to realise the system, it could be interesting to see when the alarm system is activated and to check its state. To visualise this, three LED lights are connected to the GPIO connection of the Raspberry:
- yellow to indicate if the alarm system is activated or not,
- green when the door is opened while the alarm system is activated
- red if the wrong code is encoded to unlock the alarm system (or if the delay is over).
Link to buy LED lights: https://www.amazon.fr/SODIAL-diodes-electrolumine....
Step 4: Step 4 - Remaining Materials
it’s important to talk about the rest of the material required to build the model. Lots of secondary components have to be available to finalise the project. Here is the list of components and their use:
Of course, Plexiglas, wood, screws and wires will also be required to complete the project.
Step 5: Step 5 - Model
have all those components, it’s time to start building the model. Here is the method of operating:
1. Stand up the front door and block it vertically thanks to a wood frame. After that, install the locking system. You can then test to open the door manually to make sure that it is perfectly vertical.
2. Place the contact sensors in the doorframe. Don’t forget to test them with the latch of the door to be sure they are well placed and don’t block the closing and opening. Moreover, as you have to put two sensors on this place, it’s recommended to put them in “mirror” , as you can see on the picture.
Fit them with glue or screws and pull the cables out of the doorframe. Make sure they are long enough to be connected to the breadboard.
3. Place the infrared sensors in the internal side of the house: the sensors are fitted on the frame door (on the right side, but it would work as well on the left) and the reflectors on the opposite. Notice that a DC power supply is needed to power those appliances.
You can note that for a better precision, it is recommended to have 10 cm between the two systems of sensors. Note also that if your doors open from outside to inside, you should place these sensors further.
4. Place the magnetic sensor at the left extremity of the internal side of the door (opening side). Please notice that the switch part of the sensor should be fitted on the door and the magnetic part on the doorframe. Next, connect the sensor with two electric wires long enough.
5. To realise the automated door locking, start by cut the head of the key. You also have to make slot to fit it on the electric motor.
When it’s done, put it in the locking system (inside your house) and fit the motor on it.
6. Make all the connection for the Arduino and the Raspberry like exposed on the pictures.
Then you can connect all the sensors and actuators to the Arduino via the breadboard as shown on the schematic.
But before doing all of the connection, we recommend you to fit the Arduino, the Raspberry and the ULN2003 driver on a Plexiglas. In the same idea, fit this board on a wood board: this one will be fitted on the door to create a full integrated module.
7. Place a multi-socket in the right side of the doorframe (also in the internal side) and connect every power supply. Don’t forget to connect the electric motor to the ULN2003 driver.
Your model is now ready to be used.
Step 6: Step 6 - Programming Code
Once the model is built, it’s time to talk
about the programming code. As previously mentioned, three parts have to be coded: the raspberry code, the Arduino code and the android code.
- Raspberry Code :
The Raspberry Code is programmed in the Python language (Version 3.6.1). But the first thing to do when you get a Raspberry Pi 3 is to install the Raspian Operating System. You can find the downloading link and the installation guide on the Raspberry-Pi site: https://www.raspberrypi.org/downloads/.
The next step is to install python libraries on the Raspberry. This operation is made thanks to the LX terminal of the device by encoding the command line sudo apt-get install python.
To realise the project, two python codes are needed: MainProgram.py and Server.py. Those programs don’t stop running independently from each other. The communication between those codes is done by writing data in two files: RaspberryToAndroid.txt and AndroidToRaspberry.txt. In the first text file, the raspberry code “MainProgram.py” write information (received from the Arduino for example) that are read at the end of the “Server.py” code. The second does the opposite path (information are written in the “Server.py” code and read in the “MainProgram.py” code).
You also have to download two wav files to run MainProgram.py: AlarmSound.wav and AlarmSoundLoud.wav. Those sound files are required for the Alarm System feature.
Finally, a last command line has to be encoded in the LX terminal. This one is mandatory to configure the Jack output of the Raspberry. Those one is:
amixer cset numid=3 1
Please notice that this operation has to be done every time you turn on the Raspberry.
To use the codes, you just have to download them, transfer them in the Raspberry PI (all files have to be in the same folder) and run them with the python IDLE or the LX terminal.
- Arduino Code :
The Arduino language is based on a C++ language developed for Arduino. To use the Arduino code of the project, the first step is to install the Arduino Software. It can be downloaded for Windows, Linux or Mac from the Arduino official website: https://www.arduino.cc/en/Main/Software. The installation of this program is very easy.
The Arduino programming can be done in two ways: with a computer or directly on the Raspberry PI thanks to the IDE Arduino. To use Arduino on the Raspberry, the following command line has to be encoded:
sudo apt-get install Arduino.
You can notice that to realise the Arduino code, a specific library has to be installed: . This library allow to use the different functions needed to run the motor with the ULN2003 driver. So check if this one is installed on your computer (or Raspberry).
Using this code is as simple as using the python codes: you just have to download it, to open it on Arduino and upload it in your Arduino device.
- Android Code :
The last step of the programming part consists to create an android application to communicate remotely with the Raspberry Pi. This step is done in two languages: java and xml.
The java language is used to realise the main program of the application. It is made thanks to the Android Studio program. Here is the link to download it: https://developer.android.com/studio/index.html.
The second language, xml is used to generate the interface of the application. You can notice that this code is created automatically in Android Studio when the project is created. You just have to adapt it by adding buttons or text views.
To control remotely the Raspberry code, a local network has to be configured. This one is made thanks to a router. The Raspberry is connected thanks to an Ethernet cable and generate an IP address that has to be encoded in the java code to create the communication pipe between the two devices.
An important thing to specify is that the IP address of the Raspberry change at each connection. So you have to check and correct the both codes (python and java) every time you turn on the Raspberry.
Step 7: Step 7 - How It Works
Now that the model and the programming codes have been introduced, it could be interesting to explain how this project works.
As we said before, the idea is to control remotely the alarm system and the locking system of the front door of a house. The project can be split in several features:
- The People Counter Application:
This feature allows to know how many people are in the house. It’s calculated by the python code “MainProgram.py” by analysing the state variation of the infrared sensors. The order of triggering will increase or decrease a number. This number is then sent to the Android application to display it on the screen.
- The Alarm System Application :
This part of the code control the alarm system of the house. This one can turn on the alarm system in three ways: by encoding a code through on the Smartphone, by pressing a button in the house or if nobody is in the house (People Counter Application returning zero) and if the door is locked (Locking System Application returning 1). When the system is activated, a yellow LED lights to indicate the state of the Alarm. Please notice that when you turn on the alarm system, a 15 seconds’ delay is launched. The alarm will only be really activated once this time runs out, so you have the time to go out of your house and lock your door, for example.
The unlock of the system can only be done inside the house by encoding a code on a numeric keypad. When the door is opened, a green LED turns on and a first audio file is played. This one is stopped if the right code is encoded.
Notice that you have 30 seconds to unlock the system. If the delay is over or if the wrong code is encoded, then a red LED lights and a louder audio file is played. The only way to stop it and turn off the LED is then to encode the right code.
- The Locking System Application :
The third feature concerns the automated locking system. This option can only be activated by pressing on a button of the Android application. When this button is pressed, an information is sent to the Arduino which powers the electric motor. The door latch moves until pressing the contact sensors placed in the doorframe. Those sensors send information to the Raspberry via the Arduino to stop the motor.
- The mobile Application :
Finally, let’s have a look to the design of the mobile application.
Seven information set this application:
- The title of the application (Secured and Automated Front Door)
- A text view that informs if the door is opened or not.
- A text view to show the numbers of people in the house (People Counter application)
- A Refresh button which allows to refresh the application and upload the data that come from the Raspberry
- A Lock Door button to run the locking system of the door. Please notice that this button is not available if the door is already locked: it is therefore replaced by a text view “door locked”.
- A text input (where “CODE” appears, to be replaced by the code) and arm alarm button to arm the alarm system.
- A close button to quit the application.