Skip to content

Circuit-Digest/qr-code-scanner-raspberry-pi-opencv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

QR Code Scanner Using Raspberry Pi and OpenCV

Raspberry Pi Python OpenCV License: MIT CircuitDigest

A DIY QR Code Scanner project using Raspberry Pi, OpenCV, and ZBar library to scan and decode QR codes in real-time with a camera module.

QR Code Scanner

๐Ÿš€ Features

  • Real-time QR Code Detection - Scans and decodes QR codes instantly using a camera
  • OpenCV Integration - Processes video feed for accurate QR code recognition
  • ZBar Library Support - Robust QR code decoding with high reliability
  • Display Output - Shows decoded QR code data on screen or terminal
  • Customizable - Easily adaptable for various applications
  • Cost-Effective - Affordable setup compared to commercial scanners
  • Data Logging - Option to save scanned QR code data
  • Portable Design - Compact system for versatile deployment

๐Ÿ› ๏ธ Hardware Requirements

Primary Components

  • Raspberry Pi 4B (1x) - Single-board computer (other models like 3B+ compatible)
  • Raspberry Pi Camera Module (1x) - Official camera or USB webcam
  • MicroSD Card (16GB+) - For Raspberry Pi OS and storage
  • Power Supply - 5V 3A USB-C adapter for Raspberry Pi
  • Monitor/Display - HDMI-compatible screen or SSH access
  • Keyboard and Mouse - For setup and configuration
  • Jumper Wires - For additional hardware connections (if needed)

Optional Components

  • LCD Display - For portable display output
  • Buzzer - Audio feedback for successful scans
  • LED Indicators - Visual feedback for scan status
  • External Storage - USB drive for additional data logging

๐Ÿ“ Circuit Diagram

Raspberry Pi Connections:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Raspberry Pi Pinโ”‚ Component        โ”‚ Function       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ CSI Port        โ”‚ Camera Module    โ”‚ Video Input    โ”‚
โ”‚ 5V, GND         โ”‚ Power Supply     โ”‚ Power Input    โ”‚
โ”‚ HDMI            โ”‚ Monitor          โ”‚ Display Output โ”‚
โ”‚ USB             โ”‚ Keyboard/Mouse   โ”‚ Input Devices  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“– Complete Circuit Diagram: View Detailed Schematic

โš™๏ธ Installation

1. Raspberry Pi OS Setup

  1. Install Raspberry Pi OS (Raspbian) on the MicroSD card using Raspberry Pi Imager
  2. Enable camera interface via raspi-config:
    sudo raspi-config
    # Navigate to Interface Options -> Camera -> Enable
    
  3. Update the system:
    sudo apt update && sudo apt upgrade -y
    

2. Software Dependencies

Install required libraries:

sudo apt install python3-pip python3-opencv
pip3 install zbar-py

3. Code Setup

Clone the project repository:

git clone https://github.com/Circuit-Digest/QR-Code-Scanner-Raspberry-Pi.git
cd QR-Code-Scanner-Raspberry-Pi

Run the main script:

python3 qr_code_scanner.py

๐ŸŽฏ Usage

  1. Connect the camera module or USB webcam to the Raspberry Pi
  2. Run the Python script (qr_code_scanner.py)
  3. Point the camera at a QR code
  4. View decoded data on the terminal or connected display
  5. Press q to exit the scanner

Sample Code

import cv2
import zbar
from zbar import Scanner

def main():
    cap = cv2.VideoCapture(0)
    scanner = Scanner()
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        symbols = scanner.scan(gray)
        for symbol in symbols:
            print(f"QR Code Data: {symbol.data}")
        cv2.imshow('QR Scanner', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()

๐Ÿ“ Code Structure

โ”œโ”€โ”€ Code/
โ”‚   โ””โ”€โ”€ qr_code_scanner.py           # Main QR code scanner script
โ”œโ”€โ”€ Documentation/
โ”‚   โ””โ”€โ”€ Component_Connections.md     # Detailed connections
โ”œโ”€โ”€ Circuit Diagram/
โ”‚   โ””โ”€โ”€ QR_Code_Scanner_Circuit.png # Wiring schematic
โ””โ”€โ”€ README.md                       # This file

Key Functions

  • main() - Initializes camera and processes QR code scanning
  • scanner.scan() - Decodes QR codes using ZBar
  • cv2.imshow() - Displays live video feed
  • cv2.cvtColor() - Converts frame to grayscale for processing

๐Ÿ”ง Troubleshooting

Common Issues

Camera Not Detected

  • Verify camera connection in CSI port or USB
  • Ensure camera is enabled in raspi-config
  • Check camera compatibility with Raspberry Pi

QR Code Not Decoded

  • Adjust lighting conditions for better contrast
  • Ensure QR code is within camera focus range
  • Update OpenCV and ZBar libraries

Performance Issues

  • Reduce camera resolution for faster processing
  • Use a Raspberry Pi 4 for better performance
  • Close unnecessary applications

๐Ÿ“ฑ Applications

Retail and Inventory

  • Product Scanning - Track inventory with QR codes
  • Payment Systems - Process QR-based payments
  • Asset Management - Monitor equipment usage

Education

  • Attendance Tracking - Scan student QR codes
  • Library Management - Track book borrowing
  • Event Check-in - Manage event registrations

Security

  • Access Control - QR-based entry systems
  • Visitor Management - Log visitor details
  • Ticketing Systems - Validate event tickets

๐Ÿ”ฎ Future Enhancements

  • WiFi Connectivity - ESP8266 for cloud-based logging
  • Mobile App Integration - Remote access to scan data
  • Database Support - Store scans in MySQL/MongoDB
  • Multi-Camera Support - Simultaneous scanning
  • Audio Feedback - Buzzer for scan confirmation
  • Web Interface - Real-time monitoring dashboard

๐Ÿ—๏ธ Technical Specifications

Parameter Value
Operating Voltage 5V DC
Current Consumption 2.5A (with camera active)
Camera Resolution 1080p (adjustable)
Scan Range 5-30cm
Processing Time <1s per scan
Operating System Raspberry Pi OS
Operating Temperature 0ยฐC to 50ยฐC

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contributing Guidelines

  • Follow Python PEP 8 coding standards
  • Test modifications on Raspberry Pi hardware
  • Update documentation for new features
  • Include comments for complex code sections

๐Ÿ”— Links

โญ Support

If this project helped you, please โญ star this repository and share it with others!


Built with โค๏ธ by Circuit Digest | Making Electronics Simple


Keywords

raspberry pi qr code scanner opencv qr code project diy qr code scanner zbar python project raspberry pi camera project qr code reader real-time qr scanner raspberry pi projects opencv applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages