QR Code Scanner with ESP32 CAM Module & OpenCV
DIY QR Code Scanner Reader with ESP32 CAM Module & OpenCV Python Libraries, read QR Codes using ESP32 Camera & Arduino Code
- Suitable forB.Tech/Diploma ESP32-CAM students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
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.
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.
Components
Quantity
Purchase Links
ESP32-CAM Board AI-Thinker
Amazon
AliExpress
FTDI Module
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
Jumper Wires
Amazon
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 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
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
for
Object Counting
with ESP32 CAM Module. Copy the code and paste it in the Arduino IDE.
#include <WebServer.h>
#include <WiFi.h>
#include <esp32cam.h>
const
char
*
WIFI_SSID
=
"ssid"
;
const
char
*
WIFI_PASS
=
"password"
;
WebServer
server
(
)
;
static
auto
loRes
=
esp32cam
::
Resolution
::
find
(
)
;
static
auto
midRes
=
esp32cam
::
Resolution
::
find
(
)
;
static
auto
hiRes
=
esp32cam
::
Resolution
::
find
(
)
;
void
serveJpg
(
)
{
auto
frame
=
esp32cam
::
capture
(
)
;
if
(
frame
==
nullptr
)
{
Serial
println
(
"CAPTURE FAIL"
)
;
server
send
(
""
""
)
;
return
;
}
Serial
printf
(
"CAPTURE OK %dx%d %db\n"
frame
->
getWidth
(
)
frame
->
getHeight
(
)
static_cast
<
int
>
(
frame
->
size
(
)
)
)
;
server
setContentLength
(
frame
->
size
(
)
)
;
server
send
(
"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
(
)
;
cfg
setJpeg
(
)
;
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
(
)
;
}
Serial
(
"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
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.
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.
Components
Quantity
Purchase Links
ESP32-CAM Board AI-Thinker
Amazon
AliExpress
FTDI Module
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
Jumper Wires
Amazon
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 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
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
for
Object Counting
with ESP32 CAM Module. Copy the code and paste it in the Arduino IDE.
#include <WebServer.h>
#include <WiFi.h>
#include <esp32cam.h>
const
char
*
WIFI_SSID
=
"ssid"
;
const
char
*
WIFI_PASS
=
"password"
;
WebServer
server
(
)
;
static
auto
loRes
=
esp32cam
::
Resolution
::
find
(
)
;
static
auto
midRes
=
esp32cam
::
Resolution
::
find
(
)
;
static
auto
hiRes
=
esp32cam
::
Resolution
::
find
(
)
;
void
serveJpg
(
)
{
auto
frame
=
esp32cam
::
capture
(
)
;
if
(
frame
==
nullptr
)
{
Serial
println
(
"CAPTURE FAIL"
)
;
server
send
(
""
""
)
;
return
;
}
Serial
printf
(
"CAPTURE OK %dx%d %db\n"
frame
->
getWidth
(
)
frame
->
getHeight
(
)
static_cast
<
int
>
(
frame
->
size
(
)
)
)
;
server
setContentLength
(
frame
->
size
(
)
)
;
server
send
(
"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
(
)
;
cfg
setJpeg
(
)
;
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
(
)
;
}
Serial
(
"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
Technologies used
Hardware components
- ESP32
- ESP32-CAM
- Arduino
- SD Card
Software & tools
- Arduino IDE
- EasyEDA
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.