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

20260607_170025.jpg
ESP32-CAM QR Code Locker | Open Source Offline Smart Locker System
20260613_113155.jpg
PCB_assambled.jpg

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:

  1. Temporary parcel lockers
  2. Exhibition and trade-show storage
  3. Tool checkout systems
  4. Event equipment storage
  5. Key handover lockers
  6. Educational demonstrations

The project consists of three main parts:

  1. A Python application that generates one-time QR codes.
  2. A simple website that distributes QR codes to users.
  3. 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:

https://youtu.be/wh3hpLpM9uY


The workflow is simple:

  1. Generate a set of QR codes using the supplied Python tool.
  2. Upload the generated codes to the website.
  3. Place an item into the locker.
  4. Share the website link with the customer.
  5. The customer receives a QR code.
  6. The customer presents the QR code to the scanner.
  7. The ESP32-CAM validates the code.
  8. The lock opens.
  9. 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

20260613_160851.jpg
20260613_160910.jpg
20260613_154918.jpg

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

qr_cabinet_cabeling_bb.png
20260613_113217.jpg

The locker is powered from a USB-C power bank.

Power flow:

4x18650 Batteries
USB-C Power Bank Module
PD Trigger Module (12V)
├── Electromagnetic Lock
└── XL4015 Buck Converter
5V
├── ESP32-CAM
├── Relay Module
└── Buzzer

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:

  1. No mains power required
  2. Easy deployment in temporary locations
  3. Suitable for outdoor demonstrations
  4. Can operate during power outages
  5. 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:

  1. A solenoid lock with momentary activation
  2. A motorized latch mechanism
  3. A servo-driven locking system
  4. 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:

ESP32CAM_QR_Code_Locker/

├── QR_generator_python/
├── website_qr_distribution_php/
└── QR_cabinet_lock_esp32cam/

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

QR_codes.jpg

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:

Add Python to PATH

Open a command prompt and install the required packages:

pip install qrcode[pil] reportlab

Navigate to:

QR_generator_python

Run:

generate_qr_codes.bat

The script generates:

codes.csv
codes.pdf
esp32_codes.h

qr_codes/

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

Website.jpg
website2.jpg

The website distributes QR codes to users.

Copy:

codes.csv

to:

website_qr_distribution_php/data/

Copy:

qr_codes/

to:

website_qr_distribution_php/

The structure should look similar to:

website_qr_distribution_php/

├── data/
│ └── codes.csv
├── qr_codes/
│ ├── 001.png
│ ├── 002.png
│ └── ...
└── public/

Upload the complete website_qr_distribution_php folder to a PHP-capable web hosting service using FTP.

Example URL:

https://yourdomain.com/website_qr_distribution_php/public/

Open the page in a browser and verify that QR codes can be displayed.

Prepare the ESP32 Firmware

Copy:

esp32_codes.h

generated by the Python tool into:

QR_cabinet_lock_esp32cam/include/

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:

  1. Visual Studio Code
  2. PlatformIO extension for VS Code

Open:

QR_cabinet_lock_esp32cam

using:

File → Open Folder

PlatformIO automatically downloads:

  1. ESP32 toolchain
  2. Arduino framework
  3. ESP32QRCodeReader library

This may take several minutes during the first build.

Compile the Firmware

Inside VS Code click:

PlatformIO → Build

or the checkmark icon in the bottom toolbar.

After a successful build you should see:

SUCCESS

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:

GPIO0 → GND

before powering the board.

Click:

PlatformIO → Upload

Wait for the upload to finish.

Start the Locker and Test

After programming:

  1. Disconnect power.
  2. Remove the GPIO0-GND jumper.
  3. Reconnect power.

Open the Serial Monitor:

PlatformIO → Monitor

Expected output:

QR ACCESS SYSTEM READY

The locker is now operational.

Test

Test the generated codes in the following order:

  1. Scan a normal user QR code.
  2. Verify that the lock opens.
  3. Scan the same QR code again.
  4. Verify that the code is rejected.
  5. Scan the Master Code.
  6. Verify that the lock opens.
  7. Scan the Reset Code.
  8. 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!