Welcome to Electrotek Online! Today will show you how to make an App using MIT App Inventor 2 and use it to control the Bluetooth locking system that will make use of Bluetooth module HC05 and Arduino UNO.
If you are not familiar with Arduino Uno, you can start from scratch with this previous tutorial, Arduino programming for beginners.
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 intruders.
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.
As a matter of fact, you also get to learn how to develop your own android Apps using MIT App Inventor 2.
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 (Bluetooth Locking System with Arduino and MIT App Inventor 2)
To begin building this amazing security project using an App created with an MIT App Inventor 2, you need to hookup your Arduino Uno to your computer and open the arduino IDE and include all the necessary libraries and declare all the variables and constants. The servo library was included, then an array to generate a password was created. After this, we created a few more strings and declared the password, OTP and the monitoring LED pin numbers as you can see below
The serial and Baud rate for the Bluetooth was also configured. The Baud 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.
Looping was created to check the data coming from the Bluetooth module. 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
The check() function was also created to check whether OTP is correct or not. If it’s correct then it turns the servo to open position as shown in Fig. 4 below.
The 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 2. For this project, let’s use the MIT app inventor 2 because it’s easy to use and moreover, to create an App with blocks without coding is awesome.
Building The APP with MIT App Inventor 2
Open MIT App inventor 2 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. Alternatively, you can download and import the code provided and customize it as you like.
After designing the layout in the MIT App Inventor 2 page, click on the Blocks tab which will send you to the block editing page where you can define all the logic.
From the block editing window, you can see that the Bluetooth list available was initialized first. Then a button function is set to id according to our Arduino Code as in the figure below.
Finally, export the App .apk from the MIT App Inventor 2 page and install it on your Android phone. Congratulation! you have completed the software and coding part of your bluetooth 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.
MIT App Inventor 2 Bluetooth Smart Locking: Connecting the Components.
|Arduino Pins||Components and Pin|
|Arduino Pin 9(PWM)||Servo Yellow Wire (signal input wire)|
|Rx||Bluetooth Module TX|
|Tx||Bluetooth Module RX|
The complete circuit and connections are illustrated in the picture below.
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!!
MIT App Inventor 2 Bluetooth Locking: 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.
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 only used for demonstration purposes. You can modify the MIT App Inventor 2 App and the circuit to control any locking mechanism.
If you like this Bluetooth locking system, you may consider how to use Wi-Fi to control household appliances by diving into ESP8266, NodeMCU and Wemos for Arduino IDE.
I have personally built and tested this project. I am proud to say that it works to satisfaction. if you need help or components to build this project, Whatsapp me on +233266302607