Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » QR Code Scanner with ESP32 CAM Module & OpenCV
ESP32-CAM Projects IoT Projects

QR Code Scanner with ESP32 CAM Module & OpenCV

Mamtaz AlamBy Mamtaz AlamUpdated:May 29, 20236 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
QR Code Scanner Reader ESP32 CAM
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

This project is about QR Code Scanner or Reader designed using ESP32 CAM Module & OpenCV. We will develop a program and device using ESP32 Camera module and python libraries with which we can scan QR codes. Earlier we used Maikrt QR Code Scanning Module with Arduino to read QR or barcode but the module is very expensive. Using ESP32 CAM the project becomes little cheaper.

QR Codes have now become a part of our everyday lives as we use them almost everywhere say it for payments or reaching a website or a link. Also, people add them to their resumes to share the link to their social profiles. Not just personally but large tracking and shipping companies use them to differentiate their products.

QR code is an image-like print that is encoded in a specific format that a program can decipher and decode the meaning or message in it.

QR Code Reader ESP32 Camera

Although the code is decoded by detecting the different zones and arranging the dark boxes in a specific understandable alignment. Each Dark box represents a selection or not selected. The dark spot could contain a value of 0,1,2,4,8,16,32,64 or 128,etc.


Bill of Materials

The following is the list of Bill of Materials for building an QR Code Scanner using ESP32 CAM Module. You can purchase all these components from Amazon.

S.N.ComponentsQuantityPurchase Links
1ESP32-CAM Board AI-Thinker1Amazon | AliExpress
2FTDI Module1Amazon | AliExpress
3Micro-USB Cable1Amazon | AliExpress
4Jumper Wires10Amazon | AliExpress




ESP32 CAM Module

The ESP32 Based Camera Module developed by AI-Thinker. The controller is based on a 32-bit CPU & has a combined Wi-Fi + Bluetooth/BLE Chip. It has a built-in 520 KB SRAM with an external 4M PSRAM. Its GPIO Pins have support like UART, SPI, I2C, PWM, ADC, and DAC.

The module combines with the OV2640 Camera Module which has the highest Camera Resolution up to 1600 × 1200. The camera connects to the ESP32 CAM Board using a 24 pins gold plated connector. The board supports an SD Card of up to 4GB. The SD Card stores capture images.

To learn in detail about the ESP32 Camera Module you can refer to our previous Getting Started Tutorial.


ESP32-CAM FTDI Connection

The board doesn’t have a programmer chip. So In order to program this board, you can use any type of USB-to-TTL Module. There are so many FTDI Module available based on CP2102 or CP2104 Chip or any other chip.

Make a following connection between FTDI Module and ESP32 CAM module.

ESP32 CAM FTDI Module Connection

ESP32-CAM FTDI Programmer
GND GND
5V VCC
U0R TX
U0T RX
GPIO0 GND


Connect the 5V & GND Pin of ESP32 to 5V & GND of FTDI Module. Similarly, connect the Rx to UOT and Tx to UOR Pin. And the most important thing, you need to short the IO0 and GND Pin together. This is to put the device in programming mode. Once programming is done you can remove it.


Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on a breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for ESP32 CAM Board is designed using EasyEDA online Circuit Schematics & PCB designing tool. The PCB looks something like below.

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.

Download Gerber File: ESP32-CAM Multipurpose PCB

You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.

You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.

After filling all details, select your country and shipping method. Finally you can place the order.

You can assemble the components on the PCB Board.


Installing ESP32CAM Library

Here we will not use the general ESP webserver example rather another streaming process. Therefore we need to add another ESPCAM library. The esp32cam library provides an object oriented API to use OV2640 camera on ESP32 microcontroller. It is a wrapper of esp32-camera library.

Go to the following Github Link and download the zip library as in the image

Once downloaded add this zip library to Arduino Libray Folder. To do so follow the following steps:
Open Arduino -> Sketch -> Include Library -> Add .ZIP Library… -> Navigate to downloaded zip file -> add




Source Code/Program for ESP32 CAM Module

Here is a source code for Object Counting with ESP32 CAM Module. Copy the code and paste it in the Arduino IDE.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <WebServer.h>
#include <WiFi.h>
#include <esp32cam.h>
const char* WIFI_SSID = "ssid";
const char* WIFI_PASS = "password";
WebServer server(80);
static auto loRes = esp32cam::Resolution::find(320, 240);
static auto midRes = esp32cam::Resolution::find(350, 530);
static auto hiRes = esp32cam::Resolution::find(800, 600);
void serveJpg()
{
  auto frame = esp32cam::capture();
  if (frame == nullptr) {
    Serial.println("CAPTURE FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),
                static_cast<int>(frame->size()));
  server.setContentLength(frame->size());
  server.send(200, "image/jpeg");
  WiFiClient client = server.client();
  frame->writeTo(client);
}
Void handleJpgLo()
{
  if (!esp32cam::Camera.changeResolution(loRes)) {
    Serial.println("SET-LO-RES FAIL");
  }
  serveJpg();
}
Void handleJpgHi()
{
  if (!esp32cam::Camera.changeResolution(hiRes)) {
    Serial.println("SET-HI-RES FAIL");
  }
  serveJpg();
}
Void handleJpgMid()
{
  if (!esp32cam::Camera.changeResolution(midRes)) {
    Serial.println("SET-MID-RES FAIL");
  }
  serveJpg();
}
Void  setup(){
  Serial.begin(115200);
  Serial.println();
  {
    using namespace esp32cam;
    Config cfg;
    cfg.setPins(pins::AiThinker);
    cfg.setResolution(hiRes);
    cfg.setBufferCount(2);
    cfg.setJpeg(80);
    bool ok = Camera.begin(cfg);
    Serial.println(ok ? "CAMERA OK" : "CAMERA FAIL");
  }
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.print("http://");
  Serial.println(WiFi.localIP());
  Serial.println("  /cam-lo.jpg");
  Serial.println("  /cam-hi.jpg");
  Serial.println("  /cam-mid.jpg");
  server.on("/cam-lo.jpg", handleJpgLo);
  server.on("/cam-hi.jpg", handleJpgHi);
  server.on("/cam-mid.jpg", handleJpgMid);
  server.begin();
}
Void loop()
{
  server.handleClient();
}

Before Uploading the code you have to make a small change to the code. Change the SSID and password variable and in accordance with your WiFi network.

Now compile and upload it to the ESP32 CAM Board. But during uploading, you have to follow few steps every time.

  • Make sure the IO0 pin is shorted with the ground when you have pressed the upload button.
  • If you see the dots and dashes while uploading press the reset button immediately
  • Once the code is uploaded, remove the I01 pin shorting with Ground and press the reset button once again.
  • If the output is the Serial monitor is still not there then press the reset button again.

Now you can see a similar output as in the image below.

Now the ESP32-CAM is transmitting the live video, make sure that you copy this IP address is displayed.


Python Library Installation

For the live stream of video to be visible on our computer we need to write a Python script that will enable us to retrieve the frames of the video. The first step is to install Python. Go to python.org and download Python.

Once downloaded, install Python.
Then Go to the command prompt and install NumPy, OpenCV & pyzbar libraries.

  • type: pip install numpy and press enter. After the installation is done.
  • type: pip install opencv-python and press enter.
  • type: pip install pyzbar and press enter, close the command prompt.




Python Code + QR Code Scanner ESP32 CAM

Now open Idle code editor or any other python code editor.

Now Create a new folder. Inside the folder, create a new python file and paste the code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
import numpy as np
import pyzbar.pyzbar as pyzbar
import urllib.request
 
#cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_PLAIN
 
url='http://192.168.1.61/'
cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE)
 
prev=""
pres=""
while True:
    img_resp=urllib.request.urlopen(url+'cam-hi.jpg')
    imgnp=np.array(bytearray(img_resp.read()),dtype=np.uint8)
    frame=cv2.imdecode(imgnp,-1)
    #_, frame = cap.read()
 
    decodedObjects = pyzbar.decode(frame)
    for obj in decodedObjects:
        pres=obj.data
        if prev == pres:
            pass
        else:
            print("Type:",obj.type)
            print("Data: ",obj.data)
            prev=pres
        cv2.putText(frame, str(obj.data), (50, 50), font, 2,
                    (255, 0, 0), 3)
 
    cv2.imshow("live transmission", frame)
 
    key = cv2.waitKey(1)
    if key == 27:
        break
 
cv2.destroyAllWindows()

Change the IP address copied from Arduino Serial Monitor and update it in the URL variable in the above code. Then save the code and run it.

Note: If facing an issue in pyzbar library go ahead and download Microsoft Visual C++ 2013 Redistributable (x64) – 12.0.30501 from here


Now to test the working of the project, show some QR Codes in front of the ESP32 CAM module. The computer screen will display the QR Code detail as shown in the image below.

QR Code Scanner Reader ESP32 CAM Camera Module

This is how you can build your own QR Code Scanner or Reader with ESP32 CAM Module & OpenCV Python libraries.


Video Tutorial & Guide

QR Code Reader/Scanner with ESP32 Camera Module & OpenCV
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterfacing PN532 NFC RFID Module with Arduino
Next Article Raspberry Pi Pico Web Server with ESP8266 & MicroPython

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 6 Comments

6 Comments

  1. Lam on March 17, 2022 8:27 PM

    can you post video tutorial for this project?
    I have a difficulty when i add library esp32cam , i cannot upload and run my sketch because this fault
    “Multiple libraries were found for “WiFi.h”
    ex:3:22: fatal error: esp32cam.h: No such file or directory
    compilation terminated.
    Used: C:\Users\Admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
    Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
    exit status 1
    esp32cam.h: No such file or directory”
    can you instruct me how to fix them?

    Reply
  2. Eric on March 18, 2022 3:23 PM

    when I try run code of python file and then i have a fault like this
    Traceback (most recent call last):
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 1037, in _send_output
    self.send(msg)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 975, in send
    self.connect()
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\http\client.py”, line 941, in connect
    self.sock = self._create_connection(
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\socket.py”, line 824, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\socket.py”, line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 11001] getaddrinfo failed

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “C:\Users\Admin\OneDrive\Máy tính\Project\demo\main.py”, line 15, in
    img_resp = urllib.request.urlopen(url + ‘cam-hi.jpg’)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 216, in urlopen
    return opener.open(url, data, timeout)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 519, in open
    response = self._open(req, data)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 496, in _call_chain
    result = func(*args)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 1377, in http_open
    return self.do_open(http.client.HTTPConnection, req)
    File “C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\urllib\request.py”, line 1351, in do_open
    raise URLError(err)
    urllib.error.URLError:

    Can you fix them?

    Reply
  3. qweqweq on April 17, 2022 1:39 PM

    This tutorial is not complete. Trash.

    Reply
  4. Kabir on June 9, 2022 10:40 PM

    Can we use/extend this code to send scanned QR code to webserver ? Will this code be suitable for real time application ?

    Reply
  5. David Lee on June 10, 2022 8:56 PM

    It works well after updating ESP32 from 1.6.x to 2.0.3
    use the following in Arduino IDE, File -> Prefeence -> Additional Boards Manager URLs
    https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

    Reply
  6. David Lee on June 11, 2022 3:20 AM

    I changed ESP32 from 1.6 to 2.0.3, It works fine!

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Drinking Water Quality Monitoring with ESP32
    IoT Based Drinking Water Quality Monitoring with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • DIY IoT Water pH Meter using pH Sensor & ESP32
    DIY IoT Water pH Meter using pH Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.