Bluetooth Connectivity. Retrieved from : www.pixabay.com
Welcome to Electrotek Online! Today we are going to make a Bluetooth-based locking system Which will make use of Bluetooth module HC05 and Arduino UNO. This project is much safer than the traditional key-based system and electronic wireless lock system because it can generate a new password every time a user unlocks it, which further improves your security level. One of the drawbacks of using the key-based system is the situation where your key gets lost or stolen. Moreover, the electronic wireless lock system that uses a password or passcode is not safe either. Chances are, you may forget the password and there is also a higher risk of a security breach by hackers.
Electrotek never looks down on security that is why we have come up with this unique and more secured Do-it-yourself smart locking system that will get rid of all these security threats and also provide better and robust means of locking.
These are the materials needed for this project.
List of Components
Arduino UNO
Bluetooth Hc05
Light Emitting Diode (LED)
Some Wires/Jumper Wires
Servo Motor/ Magnetic locker
5V Battery/Power Bank
USB Type B for Programming Arduino
After getting all the above components, we can start the project.
Coding
To begin, we need to include all the necessary libraries and declare all needed variables. We include a The servo library was included, then a string array to generate a password was created. After this, we created a few more string variables to store the password, OTP and monitoring LED pin numbers as you can see below
Fig 1. Arduino Code
The serial and Braud rate for Bluetooth is also configured. The Braud rate was set to 9600 but you can also use the default Braud rate of HC 05 Bluetooth module which is 38400. Then, we configured a pin for the servo using the servo. attach (PWM pin number). The monitoring LED's were also defined as OUTPUT.
Fig 2. Setting I/O and BluetoothLooping was created to check the data coming from Bluetooth. The device id is constantly check using if() statement. If it matches, then it calls otp() function for the generation of OTP as shown in Fig. 3
Fig. 3 Arduino code checking device IdThe check() function was also created to check whether OTP is correct or not. If it is correct then it turns the servo to open position as shown in Fig. 4 below.
Fig. 4 Arduino code for checking OTPThe Arduino coding part is complete. Nothing can stop you now 😎 Charlie!!! Go Go !!!
It's time to Androlize our project 😍, yes! let’s make Android APP so we can connect to the project from our phone. The App can be created with two different platforms, either Android Studio or MIT app inventor. For this project, let’s use the MIT app inventor because it’s easy to use and to create an App with blocks without coding is awesome.
Building The APP:
open MIT was initialized and log in with your Google account, create a new project and design a layout as in the picture (Fig. 5). It is just as simple as drag and drop.
Fig. 5 Layout of App in MIT app inventor
Click on the code Blocks tab, for block coding.
From the block, you can see that the Bluetooth list available for connection was initialized first. Then a button function is set to send device id according to our Arduino Code as in the figure below.
Fig. 6 MIT app inventor coding blocksFinally, export app .apk and install it on your Android phone. Congratulation! you have completed the software and coding part of your smart wireless locking system.
You can get .apk, .aia file, and code from the link below.
Now let’s set up the hardware by connecting the several components.
Connecting Components:
Arduino Pins
Components and Pin
Arduino Pin 9(PWM)
Servo Yellow Wire (signal input wire)
Rx
Bluetooth Module TX
Tx
Bluetooth Module RX
GND
GND Bluetooth
VCC
Bluetooth VCC
Pin 12
LED
GND
Battery(-VE)
The complete circuit and connections are illustrated in the picture below.
Fig. 7 Connections of components.Note!! Always crosscheck your setup to ensure that all connections are ok.
We have now completed our awesome project on the OTP-based lock system. Congratulations!!
Testing the Complete Project:
Connect the Arduino and components to a power supply. Open the installed App and turn on the Bluetooth of the phone. Tap the Bluetooth icon, you will get the list of Bluetooth connections for pairing. Select HC 05. Once pairing is successful, you will get a ‘connected’ message on the App as shown below.
Fig. 8 Showing connection status
Once the connection is established, tap on the key icon to send device id to match. You can then tap on the key again to LOCK or UNLOCK the system. The servo and onboard monitoring LED of Arduino light up indicating successful LOCK or UNLOCK. The servo was used for practical purposes. You can modify the circuit to control any locking mechanism.
This project was originally designed by Ashwini Kumar Sinha
I posted it here because I have personally built and tested it. I am proud to admit that it works to satisfaction. if you need help or components to build this project, Whatsapp me on +233266302607