Portable Battery-Powered QR Code Locker Using ESP32-CAM
by Rundhall in Circuits > Cameras
52 Views, 1 Favorites, 0 Comments
Portable Battery-Powered QR Code Locker Using ESP32-CAM
What if you could deploy a secure self-service locker anywhere without needing mains power or an internet connection?
In this project, I built a completely portable QR-code-controlled locker using an ESP32-CAM, a QR scanner, a solenoid lock, and a USB power bank. The system uses one-time QR codes that automatically become invalid after use, making it suitable for parcel pickup, equipment storage, key handover, and temporary access control.
The original design operated from a wall power supply. To make the system truly portable, I added a USB-C PD trigger module that negotiates 12 V from a standard USB power bank. This allows the entire locker system, including the electronic lock, to operate from a rechargeable battery.
The result is a self-contained access control system that can be placed almost anywhere:
- Temporary parcel lockers
- Exhibition and trade-show storage
- Tool checkout systems
- Event equipment storage
- Key handover lockers
- Educational demonstrations
The project consists of three main parts:
- A Python application that generates one-time QR codes.
- A simple website that distributes QR codes to users.
- An ESP32-CAM controller that validates QR codes and opens the locker.
Once a QR code has been used, it is permanently marked as consumed in the ESP32's non-volatile memory and cannot be used again.
A master QR code allows the owner to open the locker at any time, while a reset QR code can reactivate all generated codes.
The entire project is open source and available on GitHub:
https://github.com/rundhall/ESP32CAM_QR_Code_Locker
Video demonstration:
The workflow is simple:
- Generate a set of QR codes using the supplied Python tool.
- Upload the generated codes to the website.
- Place an item into the locker.
- Share the website link with the customer.
- The customer receives a QR code.
- The customer presents the QR code to the scanner.
- The ESP32-CAM validates the code.
- The lock opens.
- The code is permanently marked as used.
Because all code validation happens locally inside the ESP32-CAM, the locker continues to work even when no internet connection is available.
Supplies
Electronics
ItemQty
ESP32-CAM Development Board with USB Programming Adapter
1
12V Electromagnetic Door Lock (180 kg Holding Force)
1
5V 2-Channel Relay Module
1
Active Buzzer
1
XL4015 Adjustable DC-DC Buck Converter
1
USB-C Power Delivery (PD) Trigger Module
1
4×18650 USB-C Power Bank Enclosure
1
18650 Li-Ion Cells
4
Mechanical Components
ItemQty
Acrylic Storage Box
1
Self-Closing Spring Hinges
1 Set
Purchase Links
ESP32-CAM
https://www.aliexpress.com/item/1005005958341078.html
Self-Closing Spring Hinges
https://www.aliexpress.com/item/1005007384774578.html
Electromagnetic Lock
https://www.aliexpress.com/item/1005009147844566.html
Acrylic Storage Box
https://www.aliexpress.com/item/1005007751233491.html
XL4015 Buck Converter
https://www.aliexpress.com/item/1005008555232575.html
Active Buzzer
https://www.aliexpress.com/item/1005007465193498.html
2-Channel Relay Module
https://www.aliexpress.com/item/1005010459198076.html
USB-C PD Trigger Module
https://www.aliexpress.com/item/1005010018999411.html
4×18650 Power Bank Case
https://www.aliexpress.com/item/1005010407310552.html
Li-Ion Batteries
https://www.aliexpress.com/item/1005010323520949.html
How It Works
The locker is powered from a USB-C power bank.
Power flow:
This allows the locker to operate without mains power.
Note:
The current prototype uses a 12V electromagnetic lock which consumes continuous power while locked. Future versions will replace this component with a lower-power locking mechanism to improve battery runtime.
The first prototype required a wall power supply. Although functional, it limited where the locker could be installed.
To make the system portable, I added a USB-C Power Delivery trigger module. The module requests 12 V from a compatible USB power bank and provides power to the locker electronics and the solenoid lock.
Benefits of the battery-powered design:
- No mains power required
- Easy deployment in temporary locations
- Suitable for outdoor demonstrations
- Can operate during power outages
- Simple recharging using a standard USB-C charger
The power bank effectively turns the locker into a mobile access-control system that can be moved and installed wherever it is needed.
This modification transformed the project from a fixed installation into a portable battery-powered device, which is why it fits perfectly within the Battery-Powered Contest.
The locker is powered by a removable 4×18650 battery pack housed inside a USB-C power bank enclosure. A USB-C Power Delivery (PD) trigger module negotiates 12V from the power bank and supplies the lock mechanism and electronics.
While it works reliably, electromagnetic locks require continuous power to remain locked, which significantly increases battery consumption.
For a portable battery-powered system, this is not the most energy-efficient solution. A future version of the locker will replace the electromagnetic lock with a low-power alternative such as:
- A solenoid lock with momentary activation
- A motorized latch mechanism
- A servo-driven locking system
- A fail-secure electric strike
These alternatives only consume power while changing state and can dramatically increase battery runtime.
The electromagnetic lock was selected for the first prototype because of its simplicity, reliability, and ease of integration. However, reducing standby power consumption is one of the main goals for the next hardware revision.
Download the Project
Download the complete source code from GitHub:
https://github.com/rundhall/ESP32CAM_QR_Code_Locker
Extract the archive to a local folder.
You should obtain the following directory structure:
Each folder serves a different purpose:
FolderPurpose
QR_generator_python
Generates QR codes and ESP32 code database
website_qr_distribution_php
Website used to distribute QR codes
QR_cabinet_lock_esp32cam
Firmware for the locker controller
Generate QR Codes
The locker uses one-time QR codes. Every generated code can be used exactly once.
Install Python 3 from:
https://www.python.org/downloads/
During installation enable:
Open a command prompt and install the required packages:
Navigate to:
Run:
The script generates:
The console output will display a Master Code and a Reset Code.
Save these codes because they are required to manage the locker.
Prepare the Website
The website distributes QR codes to users.
Copy:
to:
Copy:
to:
The structure should look similar to:
Upload the complete website_qr_distribution_php folder to a PHP-capable web hosting service using FTP.
Example URL:
Open the page in a browser and verify that QR codes can be displayed.
Prepare the ESP32 Firmware
Copy:
generated by the Python tool into:
This file contains all valid QR codes together with the generated Master Code and Reset Code.
Without this file the firmware cannot compile.
Install the Development Environment
Install:
- Visual Studio Code
- PlatformIO extension for VS Code
Open:
using:
PlatformIO automatically downloads:
- ESP32 toolchain
- Arduino framework
- ESP32QRCodeReader library
This may take several minutes during the first build.
Compile the Firmware
Inside VS Code click:
or the checkmark icon in the bottom toolbar.
After a successful build you should see:
If compilation fails, verify that esp32_codes.h was copied into the include directory.
Step 9: Program the ESP32-CAM
Connect the ESP32-CAM programming adapter to the computer.
Connect:
before powering the board.
Click:
Wait for the upload to finish.
Start the Locker and Test
After programming:
- Disconnect power.
- Remove the GPIO0-GND jumper.
- Reconnect power.
Open the Serial Monitor:
Expected output:
The locker is now operational.
Test
Test the generated codes in the following order:
- Scan a normal user QR code.
- Verify that the lock opens.
- Scan the same QR code again.
- Verify that the code is rejected.
- Scan the Master Code.
- Verify that the lock opens.
- Scan the Reset Code.
- Verify that all user codes become valid again.
If all tests pass, the system is ready for use.
All validation occurs locally inside the ESP32-CAM and does not require an internet connection.
Have fun!