How does QR code technology work?

Scanning a QR code using a smartphone for how do QR codes work

QR or quick response code is a type of two-dimensional barcode that can store a multitude of information. We come across QR codes in our everyday life on products, web pages, magazines, promotional billboards, t-shirts, etc., but have you ever wondered how do QR codes work? Let’s learn about the technology behind QR codes.

The development of QR code

Back in 1992, there was a rising need in Japan to develop a compact code that could store more information like alphanumeric, Kanji (logographic Chinese characters) and Kana (Japanese syllabary) characters. A Japanese company called Denso Wave Incorporated were developing barcode readers at that time. To meet this rising demand, a two-member team at Denso Wave lead by Masahiro Hara embarked on the development of a new two-dimensional code. [1]

The 2D problem

In traditional barcodes, information can be coded only in one-dimension (transverse direction), while in two-dimensional (2D) codes, information can be coded in both transverse and longitudinal directions. Designing 2D codes that can be scanned as fast as possible was a major challenge for the development team because it was difficult for scanners to recognize the location of a 2D code.

Position detection pattern

One day, Hara hit on the idea of adding positional information to the code that indicates its location to scanners. Based on this idea, a position detection pattern was added at three corners of each code to allow scanners to accurately recognize 2D codes quicker.

However, designing the shape of the position detection pattern was extremely challenging because when a similarly shaped figure was added near the code, the pattern could not be recognized accurately. To prevent false recognition, the position detection pattern had to have a unique shape.

Position detection pattern in QR code
Position detection pattern. Image: Denso Wave

After surveying the ratio of white to black areas in pictures and characters printed on leaflets, magazines, corrugated cartons and other documents, the development team reduced the positional detection pattern to patterns with black and white areas. The team studied numerous printed documents and finally identified the ratio that least appeared on the printed matter. The ratio was 1:1:3:1:1.

Ratio of black and white areas in position detection pattern of QR codes
From any angle, the ratio of black and white areas in a position detection pattern is 1:1:3:1:1. Image: Denso Wave

This way, the widths of black and white areas in the position detection pattern were determined and scanners were able to detect the code regardless of the scanning angle by finding this unique ratio.

Position detection pattern in QR code
Image: Denso Wave

The QR code

After one and a half years from the start of the development, as a result of much trial and error, the QR code system that can store up to 7,089 alphanumeric characters with the additional capability to code Kanji/Kana characters was successfully developed.

QR codes were first launched in 1994 by Denso Wave for the automotive industry in Japan. QR codes allowed for high-speed component scanning and were used to track vehicles during manufacturing. QR codes quickly gained popularity outside the automotive industry due to its compact size, fast readability and greater storage capacity. [2]

Masahiro Hara the inventor of QR code
Masahiro Hara, the inventor of the QR code. Photograph: Denso Wave

How do QR codes work?

Barcodes

We all see barcodes in everyday products. Both QR codes and barcodes have their inspiration from Morse codes. Barcodes work by shining a bright LED or laser light at a series of elongated lines. We know that black absorbs light and white reflects it. The barcode scanner reads the pattern of light reflected back to its light-detecting electronic component called a photoelectric cell.

As the scanner moves past the barcode, the photoelectric cell generates a pattern of on-off pulses that correspond to the black and white stripes. An electronic decoder circuit attached to the scanner quickly converts these on-off pulses into binary digits (zeros and ones). These binary digits are sent to the computer attached to the barcode scanner, which detects the binary code.

All barcodes may look similar to the naked eye and share common features like a start and end code which allows it to be read correctly regardless of orientation. Barcodes are limited to about 20 alphanumeric characters. That is where QR or quick response codes come in.

QR codes

QR codes differ from barcodes in appearance but work the same way. Barcodes have vertical bars in varying thickness while QR codes are square-shaped and contain black squares arranged in a square grid on a white background that can be scanned by an imaging device such as a smartphone camera. Some phones may require the use of a QR reader app, which can be freely downloaded from the Android or iPhone stores.

QR codes use standard encoding modes (numeric, alphanumeric, byte/binary, and Kanji/Kana) to store data efficiently. The amount of data that can be stored in the QR code image depends on the type of data, version, and error correction level. When a QR code is read by a QR code scanner, the code is first detected by a two-dimensional digital image sensor and then digitally analyzed by a programmed processor in the device.

Versions of QR codes

QR codes come in different versions. They can range from version 1 which have 21 rows and 21 columns of modules, version 2 have 25 rows and 25 columns of modules and so on. Version 40 which have 177 rows and 177 columns of modules has the maximum storage capacity and a low error correction level, denoted by 40-L. Shown below are sample versions of QR code from version 1 to 40, indicating the overall dimensions of the symbol, i.e. 4 × version number + 17 dots on each side. [3]

Versions of QR code
Sample versions of QR codes.

Components of a QR code

Let’s learn about different parts of the QR code using a sample version 1 (21×21) QR code that we have generated..

Version 1 QR code
Version 1 (21×21) QR code example.

Modules

A module is a fundamental unit of a QR code. These are the black and white blocks that make up the data encoded in a QR code. Modules store data and makeup rows and columns of the QR code called the data matrix.

The positioning of data bits begins from the bottom right corner of the matrix and moves upward in a two-module wide column and switches direction on reaching the top as shown below.

Modules in QR code
The positioning of data bits in the QR code.

Finder patterns

The processor in the QR code reader first locates three distinctive squares (finder patterns) at three corners of the QR code image to detect the position and rotation of the code. Larger versions of QR codes includes smaller alignment structures near the fourth corner. However, the version 1 QR code shown here does not have alignment markers.

Quiet zone and finder patterns in QR code
Finder patterns.

A QR code must have white space called a quiet zone around the boundary of the QR code. The quiet zone helps the QR code scanner to locate finder patterns.

Separators

Separators help the scanner to distinguish between finder patterns and the rest of actual data in the QR code.

Separators in QR code
Separators.

Timing pattern

The next structure that occurs on all QR codes is the timing pattern. This pattern aligns with the edge of the outer positioning squares and alternates between the two colours of the code at a size of 1 module. This allows the QR code reader to confirm the version of this code and as well as the timing of the bits along both axes.

Timing pattern in QR code
Timing pattern.

Format information

The next structure on the QR code is used to denote the format of data stored in the code. Format information contains two pieces of data – the level of error correction and mask pattern.

The level of error correction

QR codes can have one of four types of error correction levels. The higher the error correction level, the lesser the storage capacity. The following table lists the approximate error correction capability at each of four levels:

Level L (Low)7% of data bytes can be restored.
Level M (Medium)15% of data bytes can be restored.
Level Q (Quartile)25% of data bytes can be restored.
Level H (High)30% of data bytes can be restored.

The first part of the format pattern denotes the level of error correction used in the code.

Level of error correction in QR code
Level of error correction.

Mask pattern

The second part of the format pattern denotes the mask that is applied to the data. Masking is the inverting of colours of modules. In masking, dark modules are converted to light and light ones to dark. Mask is used to break up large parts of identical bits to make the pattern more readable for scanners to decode the QR code. Larger versions include a format pattern that specifies the version code.

Mask pattern in QR code
Mask pattern.

There are eight different mask patterns used in QR codes and each can be represented by a formula taking in coordinates of modules to determine which modules are masked.

QR code format patterns
QR code format patterns.

Format error correction

The remaining section of the format pattern is the error correction for five bits that we have covered so far. The required data is extracted from patterns that are present in both horizontal and vertical components of the image.

Format error correction in QR code
Format error correction.

An unused data bit

The next part of the QR code is a single bit that is always represented as 1. This bit is not required for the data and the format information. It is relatively an unused part of the code.

An unused data bit in QR code
A single unused data bit represented as 1.

Data

The rest of the QR code is used to represent the stored data. The data is arranged in such a way that it starts in the lower right corner starting with the most significant bit of the data and then follows a pattern as shown below.

Data in QR code
Data in QR code.

Encoding (Enc)

The first four bits specify the type of encoding using which the data is stored. This includes numeric, alphanumeric, Kanji/Kana, whole bytes as well as other more complicated structures. Our data will be stored as whole bytes, so the corresponding encoding format is stored in the first byte of data.

Note: A QR code is able to store multiple different data types in the same code where each section starts with its own specific encoding indicator.

Message length (Len)

The second byte of data stores the message length. The text message that is stored in this QR code is Digitash. Our message is 8 bytes long which is represented in binary as 00001000 and transposed into the second byte.

The message

The next byte is stored in the ASCII capital letter “D” which is represented with the binary bits 01000100. These binary bits are transposed into the next byte in our data space. Similarly, all remaining letters of our message are stored in the next 7 bytes of data.

End of the message (End)

Following our data, the next four bits in our code is the end of message indicator. This indicator contains four zeros which are represented by four light modules in our QR code.

Error correction

Now that the message in our QR code is complete, we still have 16 remaining bytes of storage space which is used to store the error correction data of our message. QR code uses the Reed-Solomon error correction until the image can be appropriately interpreted.

After applying the Reed-Solomon error correction data and the mask pattern, our QR code is now complete. With built-in error correction, QR codes are less susceptible to damage from water or dirt. Even in harsh factory environments, QR codes can still be scanned properly. The below QR code can still scan right even with all those colours and text added over the code.

QR code explained for how do QR codes work
Complete QR code with error correction.

Conclusion

Due to its versatility, QR codes can be programmed to do a variety of things. QR codes often contain data that points to a website or application. Simply adding a QR code onto your product will allow smartphone equipped shoppers to see more detailed product information.

Some of the applications of QR codes are product tracking, item identification, website login, restaurant ordering, time tracking, document management, counterfeit detection, video games, and general marketing. QR code technology is license-free. The standard is defined in ISO/IEC 18004:2015. [4]

Share your thoughts and ideas about QR codes in the comment section below.

References
1. History of QR code
2. QR code development story
3. QR code – Wikipedia
4. ISO/IEC 18004:2015

Leave a Reply

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