Arduino Projects

QR Code/Barcode Scanner using Arduino & QR scanner module

Learn how to build an Barcode and QR code Scanner with Arduino and barcode and QR code scanner module.

Overview:

In this project we are going to learn how to interface a (1D/2D) barcode and QR code scanner module with Arduino to read the barcode or QR code data through serial monitor and OLED display. With this DIY device we can scan and read all the barcodes and QR codes through OLED display.

Generally when you go to any supermarket, malls, or an electronic stores all the products have a label with price and a barcode, which helps the seller to identify the product names, prices and quantity through the barcode. Every checkout has a cashier who scans the products using barcode scanner and produces the bill according to them.

barcode scanning at supermarket

Barcodes and QR codes are often used to track the information about the products and status in the inventory. Due to automations in the online shopping warehouses the use of QR codes had drastically increased. Scanners are placed at every routing conveyor belts to identify, route, differentiate and to track the status of the products.

Due to the revolutionary digital payment systems like UPI, most of the payments are done through QR code which made the people to pay easily and quickly without the hassle to enter all the bank information.

So, Before building a DIY Arduino Barcode scanner lets learn What are barcode and QR code, how they work? What are the required components and also learn how QR Code Scanning Module works.

Bill of Materials(Required components):

Here are the required components along with Amazon buying links at best prices.
Product NameQuantityamazon logoamazon logo india
Maikrt Embedded QR Code Scanning Module1https://amzn.to/3tsHCUnhttps://amzn.to/3sUcZYS
Arduino Nano1https://amzn.to/36Z3TBAhttps://amzn.to/3KpUQry
OLED display1https://amzn.to/34f0GNihttps://amzn.to/35HZK4E
Few Connecting Wireshttps://amzn.to/3H2BV4ehttps://amzn.to/3J0WVu2

What is barcode and How it works?

A barcode is a rectangular or square image, formed by a series of parallel lines and white spaces with a variable width that can have numerical digits at the bottom, this allows it to be scanned to get the information. Official bar codes are issued by GS1 Mexico, an organization which is responsible for making unique and standardized codes, which can be identified in any country.

What information does a barcode have?

When you first see a barcode it like a bunch of lines and numbers without much meaning, but the reality is the thickness of the bars and their distribution with respective distances are responsible to make the scanners to decode the information from them. Barcodes are made with Unique codes with numbers.

From the above image learn what each numbers means in the barcode.

what information a barcode has

Country code : indicated by the first three digits (for Mexico, for example, it is 750).

Code of the manufacturing company : it has five digits and is assigned by GS1 Mexico

Product code: can be from two to five digits and is assigned by the company (the combination can vary infinitely depending on the segment and the item).

Check digit : it is the last number and when scanned, it indicates the veracity of the code

There are several types of barcode formats which are used according to the need.

  • EAN code
  • UPC code
  • ITF Code
  • Code 128

What are QR codes and How they work?

QR code is the Abbreviation of Quick Response Code. QR Code came as an evolutionary leap from bar codes and motivated by the need to increase the amount of information and possibilities of use of what they were capable of offering.

QR code also called as 2D barcode, it includes a matrix of two-dimensional points in a square format, commonly in black and white (although there are also colors) and with three squares in the corners that allow the reader to detect the position of the code.

what qr code consists of

As you can see from the above QR code there are 3 position markers which help the scanners to locate the information modules. The data modules are square matrix boxes is a pattern the data is encoded in it. The QR code scanners decode the matrix patterns to data. QR codes provides encoding of data such as numbers, characters, symbols, URLs, vCard’s, WiFi credentials, location maps, bitcoin and crypto addresses.

How Arduino Barcode and QR code scanner works

The barcode scanner or is an electronic device that uses a built-in laser to read a barcode and output the information (the number) that the code represents, not the image. Thus, the tedious task of entering the codes disappears and the time and resources invested in it are considerably reduced. In addition, it ensures that there are no errors that would jeopardize the traceability of the sample.

barcode and qr code scanner module arduino

When the scanner is turned ON and faced towards the barcode the light source from the scanner is being absorbed by the dark bars and is being reflected by the light spaces. the barcode reader receives the reflected light and converts it into an electrical signal and the RT870 based scanner module has an in-built intelligent image recognition system which convert the signal directly into data, which is communicated through UART TTL serial port or USB interface to Microcontrollers or PC. By means of another mirror the return light is redirected to a light sensor.

In the same way Arduino 2D barcode scanner reads the QR codes and decode the data from them.

Characteristics of RT870 Maikrt Barcode scanner:

  • A small 1D/2D codes reader,
  • Can be embedded in any device for scanning code
  • intelligent image recognition algorithm.
  • Configurable via scanning ‘configuration code’.
  • Can work in the dark.
  • The performance is stable and the decoding speed is very fast.
  • Can easily capture bar codes 1D, 2D on labels, paper, and mobile phone or computer displays, Sensitive and accurately.

Maikrt Barcode scanner Pinout Diagram:

maikrt barcode scanner pinout diagram UART

 

This Barcode and QR code scanner has two communication systems USB and UART As you can see from the above pinout out diagram the UART TTL port has 9 pins from which we are connected to 4 wires where Red wire and Black wire are for powering the module with 5V and GND respectively. The GREEN wire and RED are TX and RX respectively.

You can configure the scanner module just by scanning the below QR codes for USB or UART communications and also to Restart the module.

Setup configuration of QR code and Barcode scanning module Arduino

Technical Specifications:

  • Operating Voltage: 5v
  • Power Consumption: <0.9W
  • Default Baud Rate: 9600
  • Scan distance: 5 to 10cm
  • Scanning Mode: Omni-directional Auto Sense Scan Mode
  • Scan angle: ±60°, ±40°, ±360° (left-right, front-back, rotation)

Interfacing Barcode and QR code scanner with Arduino

Lets connect all the required components to build a DIY barcode and QR Scanner using Arduino.

Interfacing Barcode and QR code scanner with Arduino

As you can see from the above circuit diagram the RED and BLACK wires from the Barcode scanner are connected to 5V and GND pins of Arduino. And the GREEN and WHITE wires are connected to D3 and D4 respectively.

Program code for barcode Scanner Arduino:

Now connect the Arduino Nano to PC where Arduino IDE is installed and copy the below code and paste it in the workspace and upload it. This code uses SoftwareSerial library which is installed by default.

//Arduino Barcode and QR code scanner http://www.circuitschools.com

#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // TX, RX
 
void setup()
{
  Serial.begin(9600);  
  mySerial.begin(9600); // set the data rate for the SoftwareSerial port
  Serial.println("Barcode scanner Arduino");
}
 
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();
  }
}

after uploading the code open the serial monitor and set the baud rate to 9600. Show some bar code or QR code over the scanner and check the output on the Serial monitor as shown in the screenshot below.

barcode and qr code scanner arduino output on serial monitor

Portable Barcode/ QR code scanner with Arduino using OLED display

Now we are connecting an OLED display to the same project to display the output on the OLED display instead of connecting the device to PC and checking the output on the serial monitor.

Interfacing Barcode and QR code scanner with Arduino nano and oled display

Here we connected the OLED display with I2C, the 2 pins VCC and GND of OLED display are connected to 5V and GND of Arduino. The SCL and SDA of OLED display are connected to A5 and A4 respectively. Connections to barcode scanner are same as above.

Program code for barcode Scanner Arduino to display on OLED display:

Now its time to upload the code to Arduino NANO. Let’s connect it to PC where Arduino IDE is installed and then install the required libraries through Arduino library manager or through the links below, which are required for OLED display.

Required Libraries:

  • Dowload Adafruit_GFX.h library – link
  • Download Adafruit_SSD1306.h library – link 

Now Copy paste the below given code into workspace and hit upload button to upload the code.

//Barcode scanner using Arduino and OLED display.
//https://www.circuitschools.com
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // TX, RX
 
#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 (128x64)
  display.print("Arduino Barcode scanner");
  delay(1000);
  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();
  }
}

After uploading the code show some bar code or QR code to the scanner, the scanner send the data to Arduino and it is sent to OLED display which we can see as the below image.

Arduino barcode scanner output on OLED display

So that’s it to test with some barcodes and QR codes search in google for barcode generator or QR code generator and create few and test them. You can show the code through your mobiles or PC also. So that’s an easy QR reader built using an Arduino. With this idea we can also build ESP32 Barcode scanner which can be display output through webserver or cloud server or through OLED display.

If you like this Project please follow our Facebook page and subscribe to our youtube channel “Circuit Schools“. If you have any doubt please hit them through the comments section below. Thanks and have a nice day.

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button