Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Raspberry Pi camera QR-code scanning

By Usman ali Butt February 16, 2021

This tutorial will teach you how to scan QR codes using the Raspberry Pi module and the official Raspberry Pi camera. To attach the camera to the Raspberry pi, we use a dedicated header is available onboard. You can also use a USB camera with Raspberry Pi. The disadvantage is USB interface is slow. Also, the Raspberry Pi USB port version is 2.0, which is slow compared to 3.0. A few extra settings and the configuration are also required to tell Raspberry that a USB camera is attached with its USB port. The official camera is easy to go with, and all support files are already installed.

Before beginning, I will assume you have already connected the camera with Pi.

First, we must enable the camera in the Raspberry config file. The easy way is to do it graphically. Go to main menu>Preferences>Raspberry Pi Configuration next window, then go to interfaces against camera select the enable button.

Now it’s time to update and install the camera packages necessary to make the camera live. Picamera is a lightweight package. It offers many functions, and above all, it’s easy to play with. I installed this package. Open the command prompt from Raspberry pi and type the following commands.

$ sudo apt-get update
$ sudo apt-get install python-picamera python3-picamera

Note: Both versions of Python 2 and 3 packages will be installed at once with the above command. It depends on you what version of python you are working with. I am working with python 3.

Another package required is zbarlight. This package decodes the QR code present in the image. To installed zbarlight, type the following commands in the command prompt.

$ apt-get install libzbar0 libzbar-dev
$ pip3 install zbarlight

Image processing package named PIL is preinstalled in the Raspberry pi. In case it is not present, you can install it with

pip install –no-index -f https://dist.plone.org/thirdparty/ -U PIL

In the code, first imported the packages at the top.

  • PiCamera package to work with Raspberry Pi camera
  • Time>sleep for delay
  • PIL for image processing
  • Zbarlight to decode and find the QR code present in the processed image.

Next, an instance of PiCamera is created named camera. Camera.start_preview() opens the camera feed, and you can see the camera view on an LCD screen to which Raspberry pi is connected. Sleep(5) control remains in sleep for 5 seconds. You can see the camera feed in these 5 seconds. Camera.capture() captures the image and store it at the location specified in the function arguments. Camera.stop_preview() ends the camera feed means no camera display on the screen.

Now starts the image decode and QR code extraction part. A variable with the name file_path assigned path to the image. With open statement opens the image as an image file. ‘rb’ means the file under consideration is not a text file. Image variable is holding the file, which is opened by PIL(Image.open(image_file)) image processing library. Image.load() loads the image. Image vectors are now present in the image variable. Vectors are then passed to zbarlight to extract the QR code from vectors. Extracted QR code is stored in the codes variable and at the end print statement prints the extracted text on the console.

Testing

I generated a QR code using an online website on my mobile. QR input text is on the left-hand side, and the encoded QR image is on the right-hand side.

I executed the code on Raspberry pi and placed the mobile in front of the camera (You can see the video on the following link https://www.facebook.com/electronicsgru/videos/548460509194441).

Decoded message is

I used Thonny default python ide in Raspberry Pi. You can run the python file from the command prompt. I suggest using any python ide. Ide will let you know any errors and type in case if some error arises.

Let’s Diy this project: Where to purchase parts?

Raspberry Pi (Mouser Electronics)
Raspberry pPi camera (Mouser Electronics)

 

You may also like:

  • Python Basics
    RPi Python Programming 06: Python basics
  • Raspberry Pi 4
    RPi Python Programming 01: Introduction to Raspberry Pi 4

  • Raspberry Pi-based smart home security system

  • Raspberry Pi 2 & 3 Vs Beaglebone Black

  • Getting started with Raspberry Pi

  • Barcode Technology – What is Barcode?

Filed Under: Electronic Projects, Raspberry pi

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe