
🚀 Raspberry Pi Barcode Scanning Project 🚀
, by Global Pi GTI, 2 min reading time
, by Global Pi GTI, 2 min reading time
✅ Summary Scan barcode → Record video → Scan again → Save to USB Use Picamera2 to record video. Support 720p video and save files as MP4. Set to run automatically when the device is turned on. 💡 Ready to use! 🎉 If you are interested in more information or to order Raspberry Pi devices and barcode scanners, please visit our website for more details!
We will use Raspberry Pi to easily control the scanning and recording of videos, and save the files to a USB Drive immediately.
🔧 Raspberry Pi installation and setup steps
Update your system and install the required packages. Open Terminal and type this command:
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip python3-opencv libopencv-dev ffmpeg -y
Enable Raspberry Pi Camera Run the command:
sudo raspi-config
Then go to:
Interface Options → Camera → Enable.
Interface Options → Legacy Camera → Enable (for new Raspberry Pi OS)
Then reboot your device:
sudo reboot
We will use the code below to scan barcode and record video:
Get the first barcode
Record 10 seconds of video
Get the second barcode
Name the video file as "barcode+datetime.mp4".
Save the file to a USB drive
⚡ Running code
After setting everything up, run the code with this command:
python3 barcode_video.py
📌 Check USB Drive
Check if the USB Drive is connected:
lsblk
If it is not mounted automatically, run this command:
sudo mount /dev/sda1 /media/pi/USB
🔄 Set to run automatically when the device is turned on.
To make the program run as soon as the Raspberry Pi is turned on:
Open the rc.local file:
sudo nano /etc/rc.local
Add this line before exit 0
:
python3 /home/pi/barcode_video.py &
press CTRL + X
→ Y
→ Enter
🚀 System Test
Plug in the barcode scanner and USB drive.
Open Terminal and run:
python3 barcode_video.py
Scan the barcode twice and check if the video file is saved to the USB Drive.
🎯 Precautions
Check if the barcode scanner is a HID Keyboard.
If using multiple USBs, you may need to adjust USB_PATH to match the mount location.
The video resolution can be changed in the record_video()
function.