ESP32Cam-Based Smart Bluetooth Lock

This post was originally published on this site

A traditional lock can pose problems if the keys required to unlock them get lost. In such a case, they will need to be replaced for security purposes. Same applies for an RFID-based lock that is dependent on the availability of an RFID tag. 

So today, we will design a smart lock that does not need any keys or RFID tags. Instead, it uses Bluetooth to directly connect to our phone and simply requires a password to gain access. 

Bill Of Material 

Let’s start our project by shopping the following components:

In addition to these, you will require an FTDI programmer or an Arduino IDE to upload the program to the ESP32 Cam and a relay to control the solenoid lock.


First, we need to add the ESP32 board to the Arduino IDE. To do so, go to File → Preferences and paste the given URL in the Board Manager URL option. After that click OK and then go to Tools → Search ESP32 and then install the board. After a successful installation, we are now ready to code., 

Fig.1 Adding board Fig 2. Setting link for adding boards Fig 3. Installing board


Now we can start our coding. Here we use the Bluetooth of the ESP32 Cam as Bluetooth serial. So first we need to include the Bluetooth serial library in the code. 

Next, we will create a string “pasw” where the password for our lock will be stored, and a new string where the password entered by the user will be saved. After that we will set the pin number of the lock to control the solenoid.

Fig 4. Code 1

Next, we will set the serial baud rate and also the Bluetooth serial name for using SerialBT.begin().

Fig 5. Code 2

After this, create a loop function for checking the availability of Bluetooth serial input given by the user. If the input is available, then we will read and save it in an empty string variable named get input. An If condition will try to create a match between the entered password and the set password. Whenever found correct, it will initiate unlock otherwise nothing will happen and the lock will remain intact.

Fig 6. Code 3


Now connect the ESP32 Cam with FTDI, program it, and then connect all the components as shown in the circuit diagram.

Fig6. Connection


Now install the Bluetooth terminal app or any Bluetooth serial supported app in Android and switch ON the phone’s Bluetooth. Then connect to Bluetooth of ESP32 and enter the correct password to unlock the lock.