Build Your Own Qr Code Lock And Manage It Through Our Apps

About the project

Our goal is to replace a regular key with a system that will open a Lock by scanning a QR Code generated on the smartphone. The entire project consists of 3 open source repos; mobile app, website and Scanner on Raspberry (ESP32 in the future)

Project info

Difficulty: Moderate

Platforms: AndroidEverything ESPHoneywellRaspberry PiPython

Estimated time: 3 hours

License: MIT license (MIT)

Items used in this project

Hardware components

Raspberry Pi Model B+ 512MB RAM Raspberry Pi Model B+ 512MB RAM We are already implementing it on ESP32, but the software isn't ready yet x 1
Mini PIR Motion Sensor Module Mini PIR Motion Sensor Module Camera turns on when movement is detected x 1
Honeywell QR scanner CM2D Honeywell QR scanner CM2D In the future we will switch to something cheaper x 1
Single channel 12v relay Single channel 12v relay Sends a signal to open the lock x 1
Connecting cables justPi female-female Connecting cables justPi female-female x 1
SD Card 8GB+ SD Card 8GB+ x 1

Software apps and online services

paho-mqtt 1.6.1 paho-mqtt 1.6.1 Provides a client class which enable applications to connect to an MQTT broker
python3-libgpiod-rpi python3-libgpiod-rpi Straightforward interface for interacting with GPIO pins via Python code
Raspberry Pi OS. Flash latest version of raspbian. (desktop no required). In the tutorial, we did it with the lite version. Raspberry Pi OS. Flash latest version of raspbian. (desktop no required). In the tutorial, we did it with the lite version.
pyserial pyserial
mosquitto mosquitto
socat socat

Hand tools and fabrication machines

Keyboard Keyboard x 1
Monitor Monitor x 1


About us:

We are a group of young students from Poland. We are creating a new project during our internship which will attract students, engineers, and technology enthusiasts.

About project:

Our goal is to replace a regular key with a system that will open a lock by reading a QR code from our smartphone. The system is based on Raspberry, but we would like to create it on a budget i.e. ESP32, so every one of you could recreate it in the garage.

How does it work?

• ⁠Generate a QR code in the mobile or website app

• ⁠Scan QR with a code reader

• ⁠The gate opens for 5 seconds

• ⁠The device sends an Event log to the website 



  1. ----------On your desktop----------
  2. Download balenaEtcher and the latest raspbian OS (without desktop)
  3. Flash OS on SD card using balena
  4. After installation skip the validation process 
  5. Flash completed
  6. -----------Raspberry Configuration------------
  7. Now plug everything up to the raspberry pi: SD card, module & sensor, ethernet, keyboard, QR scanner, hdmi, and power cable. 
  8. * If you are not sure about pins for the motion sensor and module (cause you are using a different raspberry) search the internet for the "pinout" of your device model. 

  9. When everything is plugged the raspberry will turn on automatically. 
  10. -----------System setup--------------
  11. After first boot, choose your language and keyboard layout
  12. Create a user and type a password
  13. ------------Type Following Commands-----------------
  14. sudo su
  15. passwd root (the system will ask you for a password)
  16. update repositories using: apt update  
  17. Install dependencies using: apt install python3 python3-pip socat git mosquitto (the system may ask you for more updates. Type Y)
  18. Install essential python modules: pip3 install rpi.gpio pyserial paho-mqtt
  19. Copy our repository: git clone
  20. Enter cloned folder using: cd key-scanner
  21. Install current release using:  dpkg -i KeyScanner  (press tab to autofill and enter)
  22. Enable scanner service to start on boot: systemctl enable scanner
  23. Start the service: systemctl start scanner
  24. Wait 20 seconds before the next step in order to properly start the app.
  25. --------KeyManager--------
  26. Click here to create an account on our website. 

  27. After that read all the pop-ups to understand the logic of the keys and gates. 
  28. Create gate

  29. Fill the gaps: Temporary, the serial number is a random string data type.
  30. After that get on with the key creator.

  31. Check the boxes and click create.
  32. ----------Mobile app----------
  33. Download the proper asset on your android phone and install it.

  34. After installation open the app (search for Virtual Key) and log in

  35. The next step is very important. In the app find your gate (created in the website) and slide to right in order to generate QR code. 
  36. onfiguration code to scan.

  37. Wait 20 seconds before the next step in order to configure everything well. 
  38. ----------Back to console----------
  39. Restart the scanner to apply configured data: systemctl restart scanner
  40. You can check if the data got applied successfully using: cat /etc/KeyScannerconf/magic.guid 
  41. ----------Last touch----------
  42. Open the Virtual Key app on your phone again and look for the gate (on the bottom you will find easy navigator to move between interfaces). Once you click it the QR code will generate automatically and will be ready to scan!

  43. Scan this code and wait till the relay on raspberry will turn on (red diode). It's proof that everything is working well.
  44. -------Additional Command---------
  45. cat /var/log/syslog (it will show you the latest usage of lock: OPEN/LOCK)


We managed it using SHA 256 cryptography. Check this schema to understand:

1. First part:
ID - key usage
VF & VT - valid from & valid to
L - locks matching with key

2. Second part
Combine the first part with secret code - the unique 16 signs every user (generating via website)

3. Third part
Then we want this „freak” to short using sha-256.

4. Generate QR

Useful links:




Schematics, diagrams and documents


Check how everything works together:


Website (optional)

The website is already hosted so you can use it right away, but you can check out how It works here

Key Scanner (Raspberry)

Software is written in Python and works on Raspberry (in the future there will be a new repository for ESP32)

Mobile App (optional)

Mobile Application for generating QR Codes - you can download it here


Photo of suawek013


I am a starting Software Developer. Currently a student in Technical Secondary School with a Programming Technician specialization. I have professional experience with technologies such as Laravel, Angular, React, Node.js, MySQL, SQLite, and MongoDB


Leave your feedback...