IOT

How to design Barcode + QR Code Reader using Arduino & QR Scanner Module

In this blog, we’ll learn how to create our own Barcode + QR Code Reader with Arduino and an Embedded QR/Barcode Scanner Module. The DIY QR & Barcode scanner can read information from a barcode or QR code and show it on an OLED display. The ESP32 Camera Module can also be used to construct a simple ESP32 CAM QR Scanner, although it requires a computer screen for visualization.

QR codes are commonly used in marketing and advertising efforts to track information about products in a supply chain. More recently, they’ve been crucial in tracing coronavirus exposure and slowing the virus’s spread. Barcodes are also used on products to allow for easy identification. They’re used in retail businesses to help with purchases, in warehouses to track inventory, and on invoices to help with accounting.

We’ll utilize Maikrt Embedded QR Code Scanning Module to make an Arduino Barcode + QR Code Reader. Both USB and UART Serial communication are supported by the module. It is a compact 1D/2D code reader that can be integrated into any device and used to scan codes and identify other items. It recognizes Barcode and QR Code data using a sophisticated image recognition algorithm.

We will learn what QR and Barcode are and how they work in this tutorial. Apart from that, the Maikrt Embedded QR Code Scanning Module will be discussed in detail. Finally, we’ll connect the Barcode + QR Code Scanner to the Arduino Board and show the data on the OLED Display.

Hardware Required

  • Arduino Nano
  • Maikrt Embedded QR Code Scanning Module
  • 0.96″ I2C OLED Display
  • Jumper Wires
  • Breadboard

What is Barcode & how does it work?

A barcode is a pattern of black and white bars that indicates a line of numbers printed underneath it. Barcodes are meant to be read rapidly by computers by scanning them with a red LED or laser light.

Each digit in a barcode is represented by seven vertical blocks of equal size. To symbolize the decimal numerals 0–9, these are tinted black or white. Every number is made up of four fat or thin black and white stripes, and the pattern is created so that it cannot be confused with any other number, even when turned upside down.

How does a barcode scanner work?

A barcode scanner scans printed barcodes and digitally converts them. It then decodes the information and transmits it to a computer. A lens, a light source, and a light sensor that can convert optical impulses into electrical signals make up the device. A decoder is built within a barcode scanner, and it analyses the picture data produced by the sensor before sending it to the output port. It connects to a host computer after scanning an image to send the recorded data.

The decoder recognises barcode symbols, converts bar and space content, and sends data to a computer in a format that we can understand.

What is QR Code & how does it work?

A QR code is a data-encoded scannable barcode. Encoded implies transformed into a certain format. Numeric and alphanumeric letters, bytes, and kanji are converted into a unique two-dimensional arrangement of squares in QR codes. When an optical scanner passes over those squares, the arrangement is translated back into the original form of the data.

The Data module, Position marker, and Quiet zone are the most critical components of a QR code.

The data module is the QR code’s standard unit. It usually has a black square on a white backdrop. Every QR code contains three position markers. They consist of an inner and outer eye that allows scanners and cameras to find data modules and scanning directions fast and correctly. The vacant region on all sides of the data module matrix that contains all the data modules and position markers is known as the quiet zone. It allows scanners and readers to see where the QR code starts and stops optically.

How does QR Code Scanner work?

The patterns of QR codes are binary codes that can be decoded to expose the data contained within.

The three huge squares outside the QR code can be used by a QR reader to identify a normal QR code. When it recognizes these three shapes, it understands that everything inside the square is a QR code.

The QR code is then analyzed by breaking it down into a grid by the QR reader. It examines each grid square and assigns a value to each one based on whether it is black or white. The grid squares are then grouped together to form larger patterns.

Maikrt Embedded QR Code Barcode Scanning Module

The Maikrt Embedded QR Code Barcode Scanning Module is a small 1D/2D code reader. It may be integrated onto any device to scan codes and recognize other objects. It reads QR or Barcode data using an effective image recognition algorithm. It can capture 1D and 2D bar codes on labels, paper, and mobile phone or computer displays with ease. The module has the greatest sensitivity and precision.

For direct interaction with a computer or a microcontroller, the module offers both USB and TTL ports. It comes with a 9-pin terminal line and a USB cable, making it easy to switch between the UART TTL serial port and the USB interface.

The module scans the code directly using the USB interface and communicates the result to your host computer automatically. The host computer can move on to the next phase after receiving the data. This module’s baud rate is set at 9600 by default.

For connecting with a microcontroller, the module provides a 9-pin 4-wire terminal line. The VCC (+5V) pin is red, whereas the GND pin is black. The Tx and Rx Pins are the green and white wires.

The setup code for converting between TTL and USB interfaces is as follows. You can scan the QR code of the appropriate interface based on your requirements.

Features

  • Voltage:5V
  • Power:<0.9w
  • Communication interface: UART TTL\UART RS232\USB
  • Baud Rate: 9600
  • Scanning Mode: Omni-directional Auto Sense Scan Mode
  • Parameter setting method: sweep QR code setting parameter or host command setting
  • Work tips: Buzzer can be connected, LED indicator
  • Scan angle: ±60°, ±40°, ±360° (left-right, front-back, rotation)
  • Scan Distance: 5 to 10cm
  • Working temperature: -25°C~55°C

Interfacing Barcode/QR Code Scanner with Arduino

Let’s connect the Arduino to the Barcode/QR Code Reader Scanner Module. Because the Module only requires four connections, its interface is straightforward. The following is a diagram of the connections:

Arduino QR Code Scanner

Connect the QR Bar Code Scanner Module’s red (VCC) and black (GND) wires to the Arduino 5V and GND pins, respectively. Connect the green (Tx) and white (Rx) wires to D3 and D4 on the Arduino.

Arduino QR Code Reader

Source Code/Program

The code for the Arduino QR or Barcode Reader is pretty straightforward. To read the data, we’ll utilize the Software Serial library. You can copy and paste the code into your Arduino board.



#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX

void setup()
{
Serial.begin(9600);
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}

void loop()
{
if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
{
while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
{
char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
Serial.print(input); // Print the Byte
delay(5); // A small delay
}
Serial.println();
}
}

You can place any QR Code or Barcode in front of the Module after the code has been uploaded. The module will recognize and prepare the data before displaying it on the Serial Monitor.

Portable Barcode/QR Code Scanner with Arduino & OLED Display

The above code is used to test the Barcode/QR Code Scanning Module. With the QR Code Scanner Module and Arduino, you can now combine a 0.96″ I2C OLED Display. This might be converted into a handheld device.

The complete circuit diagram along with OLED Display connections is very simple.

Arduino Barcode QR Code Scanner Reader

I2C is used to control the OLED Display. VCC, GND, SCL, and SDA are the four wires. Connect the VCC and GND pins to the Arduino 5V and GND pins, respectively. Connect the SCL and SDA pins to the Arduino A5 and A4 pins, respectively.

Arduino Barcode Reader

Project PCB Gerber File & PCB Ordering Online

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

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from https://www.nextpcb.com/

Download Gerber File: QR/Barcode Scanner PCB

Now you can visit the NextPCB official website by clicking here: https://www.nextpcb.com/. So you will be directed to the NextPCB website

  • You can now upload the Gerber File to the Website and place an order. The PCB quality is excellent. That is why the majority of people entrust NextPCB with their PCB and PCBA needs.
  • The components can be assembled on the PCB Board.

Source Code/Program

The program for the portable Arduino Barcode QR Code Scanner is as follows. For OLED Display, the code requires two libraries. i.e. Adafruit GFX Library and SSD1306 OLED Library. To get started, go to the Arduino Library folder and download the libraries from the Github link.

The code can now be copied and uploaded to the Arduino Board.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup()

{
Serial.begin(9600);
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128×64)
display.clearDisplay();
}

void loop()
{
if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
{

display.setCursor(0, 0); //oled display

while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
{
char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
Serial.print(input); // Print the Byte

display.setTextSize(2);
display.setTextColor(WHITE);
display.print(input);
display.display();
delay(5);
}
Serial.println();
display.clearDisplay();

}
}

The device will be ready for testing after the code has been uploaded. You may now begin scanning QR Codes or Barcodes.

Bring any barcode close to the Scanner Module, and it will be scanned and shown on the OLED Display.

It can scan not just barcodes but also QR codes. You can create your own QR code with the QR Code Generator website.

The OLED Display will display the right info after scanning the QR Code.

So, that’s how you may build your own portable Arduino-based QR Code Barcode Scanner or Reader for a variety of uses.

Conclusion

I hope you understand how to design a Barcode + QR Code Reader using Arduino & QR Scanner Module. We MATHA ELECTRONICS will be back soon with more informative blogs soon.

Leave a Reply

Your email address will not be published.