Arduino Based Bar Code Scanner
Arduino Based Bar Code Scanner
Supervisors
2019-2023
DECLARATION OF ORIGINALITY
We declare that this report entitled “Arduino Based Bar Code Scanner” is our own work
except as cited in the references. The report has not been accepted for any degree and is not
being submitted concurrently in candidature for any degree or other award.
We take great pleasure to express our deep sense of gratitude to our project
guide Dr. Nauman Usmani, Assistant Professor, for his valuable guidance during
the course of our project work.
We would like to thank Prof. Dr. Javed Ahmad, Head of the Department of
Physics for his encouragement.
Our utmost thanks to all the Faculty members and Non-Teaching Staff of the
Department of Physics for their support throughout our project work.
Our Family Members and Friends receive our deepest gratitude and love for
their support throughout the academic year.
Table of Contents
ACKNOWLEDGEMENTS ....................................................................................................... 3
Introduction ...................................................................................................................... 15
A Brief Note on 7805 Voltage Regulator ......................................................................... 15
Pin Diagram of 7805 Voltage Regulator IC ..................................................................... 16
Basic Circuit of 7805 ........................................................................................................ 17
How to Get Constant DC Power Supply from AC? ......................................................... 18
Important Points on 7805 Voltage Regulator IC .............................................................. 20
General Pin functions ....................................................................................................... 22
Special Pin Functions ....................................................................................................... 23
3.4 Maikrt Embedded QR Code Barcode Scanning Module............................................ 24
3.5 I2C OLED Display with Arduino ..................................................................................... 26
Modern hand held devices such as smart phones and PDAs have become increasingly powerful
in recent years. Dramatic breakthroughs in processing power along with the number of extra
features included in these devices has opened the doors to a wide range of commercial
possibilities. In particular, most cell phones regularly include cameras, processors comparable
to PCs from only a few years ago, and internet access. However, even with all these added
abilities, there are few applications that allow much passing or decryption of environmental
information. As mobile devices become more like PCs they will come to replace objects we
tend to carry around such as checkbooks, credit cards, cameras, planners, mp3 players, etc. In
short, we will be using them to accomplish our daily tasks. One application that falls into this
category is barcode reading. Current barcode readers often offer decryption of data but few
have been applied to online commerce. Specifically, we will be using an Intel Xscale PXA27x
device to simulate a barcode scanner with the added ability of adding items to a commercial
shopping cart.
‘
Chapter 01
INTRODUCTION
CHAPTER 1
INTRODUCTION
current item added. There are many possibilities for what could be stored in a barcode. We
could denote movie information, website links, a save state or item in a video game, etc.
Whatever the case may be, it can be thought of as linking information using photos taken on a
common handheld device. Thus, we have streamlined the transfer of data in a simple and
elegant manner.
1.3 Objectives
2. In this post, we will learn how to make our own Barcode + QR Code
Reader using Arduino & Embedded QR/Barcode Scanner Module. The DIY QR &
Barcode scanner can scan the Barcode or QR Code and display the read information
on the OLED Display. You can also make a simple ESP32 CAM QR Scanner using
the ESP32 Camera Module but it requires computer screen for visualization.
chain, often used in marketing and advertising campaigns. More recently, they have
played a key role in helping to trace coronavirus exposure and slow the spread of
identification. They are used in retail stores as part of the purchase process, in
4. For making Arduino Barcode + QR Code Reader, we will use Maikrt Embedded
QR Code Scanning Module. The module supports both USB and UART Serial
device for scanning code to identify other items. It uses the intelligent image
5. In this tutorial, we will learn what is QR & Barcode and how the technology works.
Apart from this, we will be going through the details of the Maikrt Embedded QR
Code Scanning Module. And finally, we will interface the Barcode + QR Code
Scanner with Arduino Board and display the read data on OLED Display.
Following is the list of components that are necessary to build the assembly the project.
➢ Arduino Uno Board
➢ Voltage Regulator(LM7805)
➢ 16×2 LCD display
➢ 13V Step Down Transformer
➢ Male and Female Header
➢ Voltage Regulator
➢ Resistors
➢ LED
➢ Potentiometer – 10kΩ
➢ OLED
➢ Push Button
Table of Contents
• Introduction
• A Brief Note on 7805 Voltage Regulator
Introduction
We are going to see about one of the most commonly used regulator IC’s, the 7805 Voltage
Regulator IC. A regulated power supply is very much essential for several electronic devices
due to the semiconductor material employed in them have a fixed rate of current as well as
voltage. The device may get damaged if there is any deviation from the fixed rate.
One of the important sources of DC Supply are Batteries. But using batteries in sensitive
electronic circuits is not a good idea as batteries eventually drain out and lose their potential
over time.
Also, the voltage provided by batteries are typically 1.2V, 3.7V, 9V and 12V. This is good for
circuits whose voltage requirements are in that range. But, most of the TTL IC’s work on 5V
logic and hence we need a mechanism to provide a consistent 5V Supply.
Here comes the 7805 Voltage Regulator IC to the rescue. It is an IC in the 78XX family of
linear voltage regulators that produce a regulated 5V as output.
They are available in several IC Packages like TO-220, SOT-223, TO-263 and TO-3. Out of
these, the TO-220 Package is the most commonly used one (it is the one shown in the above
image).
Some of the important features of the 7805 IC are as follows:
• It can deliver up to 1.5 A of current (with heat sink).
• Has both internal current limiting and thermal shutdown features.
• Requires very minimum external components to fully function.
2 GROUND Pin 2 is the GROUND Pin. It is common to both Input and Output.
3 OUTPUT Pin 3 is the OUTPUT Pin. The output regulated 5V is taken at this
pin of the IC.
The above circuit shows all the components required for a 7805 IC to work properly. The
0.22μF Capacitor near the input is required only if the distance between the regulator IC and
the power supply filter is high. Also, the 0.1μF Capacitor near the output is optional and if
used, it helps in the transient response.
In this circuit, VIN is the input voltage to the 7805 IC and the source can be from either a
battery of an unregulated DC. VOUT is the output of the 7805 IC, which is a Regulated 5V.
Components Required
• 230V-12V Step Down Transformer
• Bridge Rectifier (or 4 PN Diodes – 1N4007)
• 1A Fuse
• 1000μF Capacitor
• 7805 Voltage Regulator IC
• 0.22μF Capacitor
• 0.1μF Capacitor
• 1N4007 Diode
Working
The AC power supply from mains first gets converted into and unregulated DC and then into
a constant regulated DC with the help of this circuit. The circuit is made up of transformer,
bridge rectifier made up from diodes, linear voltage regulator 7805 and capacitors.
If you observe, the working of the circuit can be divided into two parts. In the first part, the AC
Mains is converted into unregulated DC and in the second part, this unregulated DC is
converted into regulated 5V DC. So, let us start discussing the working with this in mind.
Initially, a 230V to 12V Step down transformer is taken and its primary is connected to mains
supply. The secondary of the transformer is connected to Bridge rectifier (either a dedicated IC
or a combination of 4 1N4007 Diodes can be used).
A 1A fuse is placed between the transformer and the bridge rectifier. This will limit the current
drawn by the circuit to 1A. The rectified DC from the bridge rectifier is smoothened out with
Contents
• 1Background
• 2Technical specifications
• 3Pins
o 3.1General Pin functions
o 3.2Special Pin Functions
• 4Communication
o 4.1Automatic (Software) Reset
• 5See also
• 6References
• 7External links
Background
The Arduino project started at the Interaction Design Institute Ivrea (IDII) in Ivrea, Italy. At
that time, the students used a BASIC Stampmicrocontroller at a cost of $100, a considerable
expense for many students. In 2003 Hernando Barragán created the development
platform Wiring as a Master's thesis project at IDII, under the supervision of Massimo Banzi
and Casey Reas, who are known for work on the Processing language. The project goal was to
create simple, low-cost tools for creating digital projects by non-engineers. The Wiring
platform consisted of a printed circuit board (PCB) with an ATmega168 microcontroller, an
IDE based on Processing and library functions to easily program the microcontroller. [8] In
2003, Massimo Banzi, with David Mellis, another IDII student, and David Cuartielles, added
support for the cheaper ATmega8 microcontroller to Wiring. But instead of continuing the
work on Wiring, they forked the project and renamed it Arduino. Early arduino boards used the
FTDI USB-to-serial driver chip and an ATmega168.The Uno differed from all preceding
Arduino UNO
• LED: There is a built-in LED driven by digital pin 13. When the pin is HIGH value, the
LED is on, when the pin is LOW, it's off.
• VIN: The input voltage to the Arduino/Genuine board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated power source).
You can supply voltage through this pin, or, if supplying voltage via the power jack, access
it through this pin.
• 5V: This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 20V), the USB connector (5V), or
the VIN pin of the board (7-20V). Supplying voltage via the 5V or 3.3V pins bypasses the
regulator, and can damage the board.
• 3V3: A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50
mA.
• GND: Ground pins.
• IOREF: This pin on the Arduino/Genuino board provides the voltage reference with which
the microcontroller operates. A properly configured shield can read the IOREF pin voltage
and select the appropriate power source or enable voltage translators on the outputs to work
with the 5V or 3.3V.
• Reset: Typically used to add a reset button to shields which block the one on the board.
Each of the 14 digital pins and 6 Analog pins on the Uno can be used as an input or output,
using pinMode(),digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin
can provide or receive 20 mA as recommended operating condition and has an internal pull-up
resistor (disconnected by default) of 20-50k ohm. A maximum of 40mA is the value that must
not be exceeded on any I/O pin to avoid permanent damage to the microcontroller.The Uno has
6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024
different values). By default they measure from ground to 5 volts, though is it possible to
change the upper end of their range using the AREF pin and the analogReference() function.
• Serial / UART: pins 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-
to-TTL Serial chip.
• External Interrupts: pins 2 and 3. These pins can be configured to trigger an interrupt on
a low value, a rising or falling edge, or a change in value.
• PWM (Pulse Width Modulation): 3, 5, 6, 9, 10, and 11 Can provide 8-bit PWM output
with the analogWrite() function.
• SPI (Serial Peripheral Interface): 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins
support SPI communication using the SPI library.
• TWI (Two Wire Interface) / I²C: A4 or SDA pin and A5 or SCL pin. Support TWI
communication using the Wire library.
• AREF (Analog REFerence): Reference voltage for the analog inputs.[
The Maikrt Embedded QR Code Barcode Scanning Module is a small 1D/2D codes reader. It
can be embedded in any device for scanning code to identify other items. It uses the
intelligent image recognition algorithm for reading QR or Barcode data. It can easily capture
bar codes 1D, 2D on labels, paper, and mobile phone or computer displays. The module has
The module has both USB and TTL interfaces for direct interfacing with a computer or
a microcontroller. It is equipped with 9 pin terminal line and USB cable, which is convenient
for you to convert between the UART TTL serial port and USB interface.
Using the USB interface, the module scans the code directly and sends the result to your host
computer automatically. After receiving the data, the host computer can proceed to the next
The module has 9-pin 4-wire terminal line for interfacing with a microcontroller. The red wire
is the VCC (+5V) pin, black is the GND. The green and white wires are the Tx and Rx Pins.
The following is the setup code for conversion between TTL & USB interface. You can scan
Technical Parameters
1. Voltage:5V
2. Power:<0.9w
6. Parameter setting method: sweep QR code setting parameter or host command setting
The organic light-emitting diode (OLED) display that we’ll use in this tutorial is the SSD1306
model: a monocolor, 0.96-inch display with 128×64 pixels as shown in the following figure.
The OLED display doesn’t require backlight, which results in a very nice contrast in dark
environments. Additionally, its pixels consume energy only when they are on, so the OLED
display consumes less power when compared with other displays.
The model we’re using here has only four pins and communicates with the Arduino using I2C
communication protocol. There are models that come with an extra RESET pin. There are also
other OLED displays that communicate using SPI communication.
Pin wiring
Because the OLED display uses I2C communication protocol, wiring is very simple. You just
need to connect to the Arduino Uno I2C pins as shown in the table below.
If you’re using a different Arduino board, make sure you check the correct I2C pins:
Vin 5V
GND GND
SCL A5
SDA A4
Libraries
3. After installing the SSD1306 library from Adafruit, type “GFX” in the search box and install
the library.
Here’s some functions that will help you handle the OLED display library to write text or draw
simple graphics.
3.6 Pushbutton
A pushbutton really only has two connections, even though it has four legs.
When the button is pressed, there will be a connection between all of the legs. Otherwise, the
two top legs are connected, and the two bottom legs are, but there's no connection between the
top and the bottom.
To see how a pushbutton works, you might want to start by wiring it up to an LED -- just use
the Arduino for power and ground.’
In this project we will make Barcode + QR Code Reader using Arduino &
Embedded QR/Barcode Scanner Module. The DIY QR & Barcode scanner can scan the
Barcode or QR Code and display the read information on the OLED Display. You can also
make a simple ESP32 CAM QR Scanner using the ESP32 Camera Module but it requires
QR codes are frequently used to track information about products in a supply chain, often
used in marketing and advertising campaigns. More recently, they have played a key role in
helping to trace coronavirus exposure and slow the spread of the virus. Similarly, Barcodes are
applied to products as a means of quick identification. They are used in retail stores as part of
the purchase process, in warehouses to track inventory, and on invoices to assist in accounting.
For making Arduino Barcode + QR Code Reader, we will use Maikrt Embedded QR Code
Scanning Module. The module supports both USB and UART Serial communication. It is a
small 1D/2D codes reader that can be embedded in any device for scanning code to identify
other items. It uses the intelligent image recognition algorithm to identify the Barcode and
QR Code data.
In this tutorial, we will learn what is QR & Barcode and how the technology works. Apart
from this, we will be going through the details of the Maikrt Embedded QR Code Scanning
Module. And finally, we will interface the Barcode + QR Code Scanner with Arduino Board
of black and white bars. Barcodes are designed for computers to read quickly by scanning
Each digit in a barcode is represented by seven equal-sized vertical blocks. These are colored
in either black or white to represent the decimal numbers 0–9. Every number ultimately
consists of four fat or thin black and white stripes and its pattern is designed so that, even if
you turn it upside down, it can’t be confused with any other number.
sends the data to a computer. It consists of a lens, a source of light, and a light sensor that can
translate optical impulses into electrical signals. A barcode scanner contains a decoder that
analyses the image data provided by the sensor and sends it to the output port. After scanning
The decoder recognizes the barcode symbols, translates the bar and space content, and
particular form. In the case of QR codes, numeric and alphanumeric characters, bytes, and kanji
passes over those squares, it translates their arrangement back into that data’s original form.
The most important parts of a QR code are the Data module, Position marker & Quiet zone.
The data module is the standard unit of the QR code. It’s typically a black square set against
a white background. There are three position markers on every QR code. Consisting of an
inner and outer eye, they allow scanners and cameras to quickly and accurately locate the data
modules and the scanning direction. The quiet zone is the blank area on all sides of the data
module matrix that contains all the data modules and position markers. It allows scanners and
code’s data.
A QR reader can identify a standard QR code based on the three large squares outside the QR
code. Once it has identified these three shapes, it knows that everything contained inside the
square is a QR code.
The QR reader then analyzes the QR code by breaking the whole thing down to a grid. It looks
at the individual grid squares and assigns each one a value based on whether it is black or
The Maikrt Embedded QR Code Barcode Scanning Module is a small 1D/2D codes reader.
It can be embedded in any device for scanning code to identify other items. It uses the
intelligent image recognition algorithm for reading QR or Barcode data. It can easily capture
bar codes 1D, 2D on labels, paper, and mobile phone or computer displays. The module has
The module has both USB and TTL interfaces for direct interfacing with a computer or
a microcontroller. It is equipped with 9 pin terminal line and USB cable, which is convenient
for you to convert between the UART TTL serial port and USB interface.
Using the USB interface, the module scans the code directly and sends the result to your host
computer automatically. After receiving the data, the host computer can proceed to the next
The module has 9-pin 4-wire terminal line for interfacing with a microcontroller. The red wire
is the VCC (+5V) pin, black is the GND. The green and white wires are the Tx and Rx Pins.
The following is the setup code for conversion between TTL & USB interface. You can scan
Technical Parameters
1. Voltage:5V
2. Power:<0.9w
6. Parameter setting method: sweep QR code setting parameter or host command setting
Module onl requires 4 connection, so its interfacing is fairly simple. The connection diagram
is as follows
Connect the red wire (VCC) & black wire (GND) of the QR Bar Code Scanner Module to
Arduino 5V & GND pin respectively. Similarly, connect the green wire (Tx) and white wire
1 #include <SoftwareSerial.h>
2 SoftwareSerial mySerial(3, 4); // RX, TX
3
4 void setup()
5 {
6 Serial.begin(9600);
7 mySerial.begin(9600); // set the data rate for the SoftwareSerial port
8 }
9
10void loop()
11{
12 if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
13 {
14 while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is
15empty
16 {
17 char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
18 Serial.print(input); // Print the Byte
19 delay(5); // A small delay
20 }
21 Serial.println();
22 }
}
After the code is uploaded, you can bring any QR Code or Barcode in front of the Module. The
module will identify and ready the data snd display the read data on Serial Monitor.
can integrate 0.96″ I2C OLED Display with the QR Code Scanner Module and Arduino. This
The complete circuit diagram along with OLED Display connections is very simple.
The OLED Display is an I2C Module. So it has 4 wires as VCC, GND, SCL & SDA. Connect
the VCC & GND pin to Arduino 5V & GND Pin. Similarly, connect the SCL & SDA Pin to
Source Code/Program
The following is the program for portable Arduino Barcode QR Code Scanner. The code
requires two libraries for OLED Display, i.e. Adafruit GFX Library and SSD1306 OLED
Library. First download these libraries from Github link and add it to the Arduino Library
folder.
1 #include <Wire.h>
2 #include <Adafruit_GFX.h>
3 #include <Adafruit_SSD1306.h>
4 #include <SoftwareSerial.h>
5 SoftwareSerial mySerial(3, 4); // RX, TX
6
7 #define SCREEN_WIDTH 128 // OLED display width, in pixels
8 #define SCREEN_HEIGHT 64 // OLED display height, in pixels
9 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
10
11Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
12
13void setup()
14{
15 Serial.begin(9600);
16 mySerial.begin(9600); // set the data rate for the SoftwareSerial port
17 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C
18(128x64)
19 display.clearDisplay();
20}
21
22void loop()
23{
24 if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
25 {
26 display.setCursor(0, 0); //oled display
27
28 while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is
29empty
30 {
31 char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
32 Serial.print(input); // Print the Byte
33
34 display.setTextSize(2);
35 display.setTextColor(WHITE);
36 display.print(input);
37 display.display();
38 delay(5);
39 }
40 Serial.println();
41 display.clearDisplay();
}
}
Chapter 5
Conclusion and References
5.1 CONCLUSION
The barcode scanner works very close to how we expected. Because the provided camera has neither
autofocus nor flash, it was often difficult to determine the exact cause of problems. However, after
extensive testing we were able to produce a working scanner with good results. Thanks to efficient
image conversion and decoding processes, the entire process runs predictably within reasonable time
constraints; roughly a few seconds. As far as resources are concerned, waste is kept low thanks to our
pipelined data processing approach. Although decoding often takes up the majority of the process, the
time it takes is usually constant. Therefore, the network connection can be considered the major
bottleneck since it may produce uncontrollable results. Barcode decoding with mobile devices is
definitely possible with the correct implementation. Yet in practice, results are dependent on the quality
of the camera as well as the speed of the network connection.
5.2 REFERENCES