Every time you go on shopping sprees at a supermarket, the long queues at checkouts may cause you to become upset.
But now, thanks to technology development, the emergence of self-service cashiers in supermarkets brings us a lot of conveniences.
Can we make a self-service cashier with HuskyLens? What we need to identify each and every product
accurately and estimate final bill?
Learning Objectives
1. Learn the working principle and application field of barcode.
2. Learn to use the barcode recognition function of HUSKYLENS.
3. Use the barcode recognition of HUSKYLENS to make a self-service supermarket cashier.
Preparation

Learning Content
If we have a close-up view on the process of check-out, we will find whether it is a manual or self-service cashier, it’s all the same: scan the barcode of the product and calculate the bill. As the barcode of each product is different, we only need to find replacements for code scanner and barcode to realize our project.

Scanning devices---- the tag recognition function of HUSKYLENS
Barcodes----- Any Tags
working principle and application field of barcode
1. What is barcode technology?
Bar code is a symbol that expresses certain information composed of a group of bars, spaces and their corresponding characters arranged in a regular manner. Different code systems have different composition rules for bar code symbols. At present, the more commonly used code systems are EAN barcode, UPC barcode, 2/5 barcode, interleaved 2/5 barcode, Codabar, 93 barcode, 128 barcode and so on.
Barcode technology is an emerging technology that integrates coding, printing, recognition, data collection and processing developed on the basis of Computer Information Technology. The core content of bar code technology is to use photoelectric scanning equipment to read bar code symbols, so as to realize the automatic recognition of the machine, and quickly and accurately input the information into the computer for data processing, in order to achieve the purpose of automatic management.

2. Working principle of barcode technology
The barcodes compiled according to certain rules need to go through the processes of scanning and decoding to be converted into meaningful information. The color of an object is determined by the type of light it reflects. A white object can reflect various wavelengths of visible light, and a black object can absorb various wavelengths of visible light.
Therefore, after the light emitted by the light source of the barcode scanner is reflected by the barcode, the reflected lights shine over the photoelectric converter inside the barcode scanner, and the photoelectric converter converts the reflected light signal into corresponding electrical signal according to the different intensity of the reflected light signal.
3. Application field of barcode technology
Retail Industry
The most common use of barcodes is in the retail industry. EAN commodity barcodes build the foundation for the retail industry to apply barcodes. At present, most of the commodities sold in supermarkets use EAN barcodes. When selling, the cashier scans the EAN barcodes with a scanner. The POS system finds the corresponding name, price and other information from the database, and counts the commodities purchased.
Library
Barcodes are also widely used in the circulation of books in libraries. Barcodes are affixed to books and library cards. When borrowing books, you only need to scan the barcode on the library card, and scan the barcode on the book, then the relevant information will be automatically recorded in the database.
Warehouse Management and Logistics Tracking
For the occasion of the mass flow of commodity goods, the application of barcode technology can realize fast and accurate recording of each item, and the various data collected can be processed by the computer system in real time. This enables various statistical data to accurately and timely reflect the status of items.
Can you find other applications of Barcode in daily life?
Demonstration of HUSKYLENS barcode recognition Function
1. Detect barcode
When detected by HuskyLens, all of the barcodes will be selected by orange frames on the screen automa nded to put a piece of white paper under the paper cards.
2. Learn barcodes
Now, learn and recognize the following three paper cards. (Note: The barcode on the front and back is the same).

Point the "+" symbol at the barcode, long or short press the "Learning button" to complete the first barcode learning. After releasing the "Learning Button", the screen will display: "Press the button again to continue! Press other buttons to end. " To continue learning the next barcode, press the "Learning button" before the countdown ends. If you no longer need to learn other barcodes, press the "Function button" before the countdown ends, or do not operate and wait for the end of the countdown.

In this project, we are going to learn multiple barcodes. Therefore, we need to short press the “Learning Button” before the countdown ends. Then, point the “+” at the second barcode, pressing or holding the “Learning Button” to complete this learning, and so on.
The tag ID is in the same order as the tag entered. That is, the learned tags will be tagged "Tag: ID1", "Tag: ID2", "Tag: ID3", and so on. Moreover, different tags correspond to different frame colors.
3. Recognize barcodes
When the HUSKYLENS encounters the learned barcodes again, there will be a colored frame to select them and display their IDs on the screen. The size of the frame can change with the size of barcodes and track barcodes automatically.

Project Practice
We will finish the project in two tasks. Firstly, use the barcode recognition function of HUSKYLENS to learn and recognize three products with barcodes, and then display the price on the HUSKYLENS screen.
Secondly, based on the previous step, add the start and end of the scanning code events to perform quantity statistics of customer’s products. At last, add the total price settlement function to realize the supermarket self-service cashier function.
Task1: Price displaying
Let HUSKYLENS learn and recognize the barcodes of three different products. Write a program to make HUSKYLENS display the prices of the successfully recognized product on the screen.
Task 2: Price settlement
Based on task 1, add the product price settlement function. When any learned product is recognized, the price of a single product will be added to the total price.
Task1: Price displaying
Hardware connection
Program Design
Function instruction:
There are various products in the supermarket, and each one has a corresponding barcode and price. Now let HUSKYLENS learn three products in turn: fruit, candy, and toy. Assuming that the price of each product is: fruit (7 yuan), candy (4 yuan), toy (15 yuan), display the corresponding price of each product on the HUSKYLENS screen.
Flowchart analysis
Sample program
Operating Effect
When the barcode is successfully recognized, the buzzer on the micro:bit will emit a mid-tone Do, and the corresponding price of the product will be displayed on the HUSKYLENS screen.

Task2: Price settlement
Hardware connection
Program design
Function instruction:
To ensure that the total price of the items being settled matches the actual total price of the items the customer has purchased, we can control the scanning process based on the number of button presses.
When the customer presses the button for the first time (count +1, count modulo 2 equals 1), scanning begins, and the HUSKYLENS screen displays the name of the item being recognized. When the button is pressed again (count +1, count modulo 2 equals 0), scanning ends, and the HUSKYLENS screen shows the total price of the scanned items. After scanning ends, no further items will be displayed for that customer. When the next customer presses the button, a new scanning process will begin.
Flowchart analysis
Sample program:
Operating Effect
Once the button is pressed, the process of scanning the product barcode begins. When the barcode is successfully recognized, the corresponding product price will be displayed on the screen. When the button is pressed again, the scanning ends, and the screen will show the total of the unit prices of the scanned items.
Project Review
This project mainly uses barcode recognition technology to recognize the corresponding product information and output a specific ID so as to display the product prices on the HUSKYLENS screen and realize the function of settlement. Now the supermarket self-service cashier system is basically done.
Project Development
Normally, there is a locker for free storage at the entrance of the supermarket. Before storing things, press the "Store" button, the locker will print a barcode, and the corresponding locker will automatically open when you get the barcode. Can you use the HuskyLens to complete the locker project?
