How do QR codes work?β
|
β "βFloorGobanβ" by βGoban1β is part of the public domain. |
A QR (Quick Response) code is a grid of black and white squares that a scanner can interpret as bits using image processing, with black squares representing "1" and white squares "0."
QR codes have a lot of advantages: they can be scanned from any direction, hold much more data than a traditional barcode, and can even still work with up to 30% of the code being damaged.
It's important to note that a QR code only stores encoded data. The device that reads the data recognizes what kind of content it is, and then decides what action to offer, like opening a URL, saving a contact, or joining Wi-Fi.
A QR code may look like a random assortment of black and white squares, but there's a method to the madness. Here's a labeled image of QR code of todayyoushouldknow.com as an example.
Each section of the QR code serves a distinct purpose: to help align the scanner, communicate the type and content of data, and add redundancies for error correction.
Finder Patterns
Likely the most recognizable element of a QR code's design, the three squares on a QR code are the finder patterns. The fourth corner is intentionally left empty to tell a scanner which way is "up." The QR code must be surrounded by a blank "quiet zone" to help scanners detect the finder patterns.
Timing Pattern
The timing pattern is a row and column of alternating black and white modules (squares that make up the QR code). It helps the scanner determine the size of each module.
Alignment Pattern
Depending on the size of the QR code, you may find one or more smaller squares in the design. These smaller squares, known as alignment patterns, help the scanner correct for distortion if the code is scanned at an angle or if the code is on a curved surface.
Format Information
Format information tells the scanner key information about how the QR code is encoded. It contains the mask pattern and error correction level.
A mask pattern is a rule that tells the QR code to flip certain modules from black to white, or vice versa. This helps break up large blocks, stripes, or other patterns that could make the code harder for a scanner to read. The code also includes which mask was used, so the scanner can reverse it and recover the original data correctly.
Error Correction
Depending on the level, error correction allows a QR code to still be read even if up to 30% of it is damaged or missing. This is how you often see QR codes with logos smack dab in the middle.
In basic terms, error correction adds backup data so a scanner can still recover data if it's damaged, blurry, or obscured. It uses a method called Reed-Solomon error correction, carefully calculated redundant data so the scanner can detect and reconstruct missing or corrupted pieces. If you want to dig into the math behind it, Veritasium has a great video on it.
Data Content
The bulk of the QR code is devoted to the actual data content being stored. The bits start in the bottom right corner and zig-zag upward in two-column strips until the entire data region is filled.
Here's an example of how you'd encode "Hi" into a QR code using binary:
The first four data bits, in the bottom right of the QR code, tell the scanner how to interpret the following modules, or bits. In this example, 0100 means byte mode. The next 8 modules communicate how much data will follow. And then the remaining modules contain the actual data.
|
--- Thanks for reading this week's newsletter! If you have any thoughts, questions, or favorite GIFs, my inbox is always open. Just hit reply to send me a note! :) All my best, |
βSources for this week's newsletterβ
|
"The Union of Conscientiously Work-Shy Elements was an unusually successful frivolous political party in Denmark.... Comedian Jacob Haugaard...was very unexpectedly elected to the Folketing with 23,253 personal votes, thereby winning a constituency seat (a locally based seat in parliament).
He made the following promises in the 1994 election (abbreviated list):
*indicates promises that were fulfilled during his term in office
P.S. π€ Do you have a question for the newsletter? Click here to submit your question (or reply to this email!)
|
Learn something new every Friday. Join 2,000+ nerds and satisfy your curiosity one question at a time with topics including science, technology, history, and more.
How do contact lenses work? This question came from a reader submission (thanks anonymous!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question π The short answer Contact lenses correct refractive errors, like nearsightedness, farsightedness, and astigmatism, by using precisely shaped lenses to bend incoming light so it lands on the retina instead of in front of or behind it. π The long answer As someone with a mild aversion to putting...
Why do nuthatch birds walk upside down? This question came from a reader submission (thanks Nancy!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question π The short answer Nuthatches climb down trees headfirst to forage more efficiently. By approaching the bark from above, they can spot hidden food that upward-climbing birds may miss. π The long answer Say hello to the nuthatch. ππ "Sitta-carolinensis-001" by Mdf is licensed under CC...
Can the brain heal itself after a stroke? This question came from a reader submission (thanks Aunt Genie!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question π The short answer After a stroke, the brain can reorganize its neural pathways to recover lost functions through neuroplasticity. The best way to promote healing is consistent practice of the affected functions, like deliberately using the weaker side of the body for everyday...