0% found this document useful (0 votes)
320 views54 pages

Barcode-Based Product Classification

With this product classification system project based on barcode, classifying products will become easier and more accurate, leading to a reduction in labor force within the factory. The GM65 scanner is used to recognize barcode types, send data to the ATmega328 microcontroller on the Arduino board to control the sensors and servo motors accurately to set up the products. Finally, the output data is displayed on the LCD screen for easy monitoring of the operation process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
320 views54 pages

Barcode-Based Product Classification

With this product classification system project based on barcode, classifying products will become easier and more accurate, leading to a reduction in labor force within the factory. The GM65 scanner is used to recognize barcode types, send data to the ATmega328 microcontroller on the Arduino board to control the sensors and servo motors accurately to set up the products. Finally, the output data is displayed on the LCD screen for easy monitoring of the operation process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

THE BARCODE-BASED PRODUCT CLASSIFICATION

SYSTEM
ABSTRACT
With this product classification system project based on barcode, classifying
products will become easier and more accurate, leading to a reduction in labor force
within the factory. The GM65 scanner is used to recognize barcode types, send data
to the ATmega328 microcontroller on the Arduino board to control the sensors and
servo motors accurately to set up the products. Finally, the output data is displayed
on the LCD screen for easy monitoring of the operation process.
TABLE OF CONTENTS
ACKNOWLEDGMENT..................................................................................................II

LIST OF FIGURE...........................................................................................................XI

LIST OF TABLES........................................................................................................XIII

CHAPTER 1: OVERVIEW OF THE TOPIC..............................................................1

1.1 INTRODUCTION OF THE TOPIC:...................................................................................1


1.2 RESEARCH PURPOSE:..................................................................................................1
1.3 RESEARCH OBJECT:....................................................................................................2
1.4 RESEARCH SCOPE:......................................................................................................2
1.5 EXPECTED RESULTS:...................................................................................................2

CHAPTER 2: THEORETICAL BASIS........................................................................3

2.1 OVERVIEW OF THE ARDUINO UNO - CONTROLLER BOARD:.......................................3


2.1.1 Introduction to Arduino Uno:.............................................................................3
2.1.2 Arduino Uno R3 - Structure and Hardware:......................................................4
2.1.3 Pinout diagram of Arduino Uno R3:..................................................................5
2.1.4 Power supply:.....................................................................................................5
2.1.5 I/O Pins:..............................................................................................................6
2.2 ARDUINO IDE SOFTWARE OVERVIEW:......................................................................8
2.3 GENERAL ABOUT BARCODES AND SCANNERS GM65:................................................8
2.3.1 Barcode concept:................................................................................................8
2.3.2 Common types of barcodes:................................................................................9
2.3.3 How Barcode works:........................................................................................13
2.3.4 Classification of barcode scanners and barcode recognition methods:...........13
2.4 SERVO DC MOTOR OVERVIEW:................................................................................16
2.4.1 What is a servo motor?.....................................................................................16
2.4.2 Working principle of servo motor:....................................................................16
2.5 OPERATING PRINCIPLE OF INFRARED SENSORS:.......................................................18

CHAPTER 3: DESIGN AND CONSTRUCTION.....................................................19

3.1 THE BLOCK DIAGRAM OF THE SYSTEM:...................................................................19


3.1.1 Power Block:.....................................................................................................19
3.1.2 Code Scan Block:..............................................................................................21
3.1.3 Processing block:..............................................................................................23
3.1.4 Sensor Block:....................................................................................................23
3.1.5 Motor Block:.....................................................................................................24
3.1.6 Display block:...................................................................................................26
3.2 GENERAL PRINCIPLE DIAGRAM:...............................................................................29

CHAPTER 4: PROCEED TO IMPLEMENT............................................................30

4.1 SYSTEM OPERATION:................................................................................................30


4.2 ALGORITHM FLOWCHART OF THE SYSTEM:..............................................................30

CHAPTER 5: EXPERIMENT.....................................................................................32

5.1 EXPERIMENTAL PROCESS:........................................................................................32


5.1.1 Designing printed circuit:.................................................................................32
5.1.2 Printed circuit construction:.............................................................................33
5.1.3 Load the program and run the printed circuit:.................................................35
5.2 EXPERIMENTAL RESULTS:........................................................................................37
5.3 EXPERIMENTAL CONCLUSIONS:................................................................................38

CHAPTER 6: CONCLUSION.....................................................................................39

6.1 ADVANTAGES:..........................................................................................................39
6.2 DISADVANTAGES:.....................................................................................................39
6.3 DIRECTION OF DEVELOPMENT:.................................................................................39

REFERENCES.................................................................................................................41

APPENDIX ....................................................................................................................43
LIST OF FIGURE

Figure 2-1 Pinout diagram of Arduino Uno R3..........................................................5


Figure 2-2 Interface of Arduino IDE 2.0.4.................................................................8
Figure 2-3 UPC barocde...........................................................................................10
Figure 2-4 EAN barcode...........................................................................................10
Figure 2-5 Code 39...................................................................................................10
Figure 2-6 Code 128.................................................................................................11
Figure 2-7 QR code...................................................................................................12
Figure 2-8 Matrix code.............................................................................................12
Figure 2-9 PDF417 barcode......................................................................................12
Figure 2-10 How barcodes work...............................................................................13
Figure 2-11 Structure of Laser Barcode Reader.......................................................15
Figure 2-12 The principle of reading barcodes.........................................................15
Figure 2-13 Working principle of servo motor.........................................................17
Figure 2-14 Operating principle of infrared sensors.................................................18
Figure 3-1 The block diagram of the system............................................................19
Figure 3-2 Specifications of IC 7805........................................................................20
Figure 3-3 Power Block diagram..............................................................................20
Figure 3-4 The GM65 barcode reader module..........................................................21
Figure 3-5 Processing Block.....................................................................................23
Figure 3-6 Infrared sensor.........................................................................................23
Figure 3-7 Wiring diagram for sensors.....................................................................24
Figure 3-8 Servo motor.............................................................................................25
Figure 3-9 Wiring diagram of servo motors.............................................................25
Figure 3-10 LCD Screeen.........................................................................................26
Figure 3-11 Wiring diagram of LCD with arduino...................................................28
Figure 3-12 General principle diagram.....................................................................29
Figure 4-1 Algorithm flowchart of the system.........................................................31
Figure 5-1 PCB circuit..............................................................................................32
Figure 5-2 PCB circuit..............................................................................................33
Figure 5-3 Printing circuit into paper........................................................................33
Figure 5-4 Complete printed circuit..........................................................................34
Figure 5-5 Circuit after attaching component pins...................................................35
Figure 5-6 LCD displays...........................................................................................36
Figure 5-7 Completed system...................................................................................37
LIST OF TABLES

Table 2-1: Specifications of Arduino Uno R3............................................................5


Table 3-1 specifications............................................................................................20
Table 3-2 Specifications of GM65 barcode reader module......................................21
Table 3-3 Specifications of LCD..............................................................................27
PROJECT OF EMBEDDED SYSTEM
PAGE 1

CHAPTER 1: OVERVIEW OF THE TOPIC

1.1 Introduction of the topic:

Nowadays, our country is entering the era of industrialization and


modernization, according to the trend of automation and rapid development.
Therefore, it requires us to focus on improving and building production systems in
order to reduce production costs, enhance labor productivity and produce high-value
products.
It can be seen that product classification is a simple but essential requirement in
factories, especially product classification based on various criteria to replace
human labor. Product classification brings many benefits, such as replacing and
reducing labor force, avoiding boredom at work, improving working conditions,
creating opportunities to access advances in science and technology and working in
a new and increasingly civilized environment.
In addition, product classification helps to improve labor productivity, create a
premise for reducing product costs, and quickly change product models. It also
simplifies management and monitoring, as it not only changes the working
conditions of workers but also minimizes the number of required workers.
There have been many automated systems applied and implemented, all of
which are relatively complex systems. With their knowledge and understanding of
reality, they have undertaken the project "The barcode-based product classification
system".

1.2 Research purpose:

The design consists of a product classification system tailored to the


requirements of the production line, which uses The GM65 barcode reader module
capable of scanning both 1D and 2D barcodes to input data into the central
processing unit, the Arduino Uno microcontroller, to control two servo motors to
properly sort the scanned product.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 2

1.3 Research object:

Understanding popular barcode standards: Understand popular barcode


standards such as UPC, EAN, Code 128, Code 39, etc. to understand how products
are identified and classified using these codes.
Barcode reading technology: Learn about modern barcode reading technologies
such as optical scanning, image sensing, RFID, etc. to increase reading speed and
accuracy.
Learn about capacitor components, voltage regulators, and ICs.
Learn about GM65 barcode scanner.
Learn about the Arduino Uno microcontroller, Atmega328 chip, and Arduino
software.
Learn about the sg90 servo motor and its operation.
Learn how to connect and operate the LCD 1602 display.

1.4 Research scope:

The device uses 12VDC power, used anywhere with small items that can be
sorted.

1.5 Expected results:

The system has the ability to read and process information stably when facing
different situations such as scanning multiple barcodes in a short period or scanning
different types of barcodes.
It can classify three different types of products.
The sensor and servo motor only operate when the correct product is detected.
The display shows the barcode and the number of products that have been
classified.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 3

CHAPTER 2: THEORETICAL BASIS

2.1 Overview of the Arduino Uno - controller board:

2.1.1 Introduction to Arduino Uno:

Arduino is an open-source platform used for building electronic projects and a


microcontroller board used for programming to interact with hardware devices such
as sensors, motors, lights, and many other devices.
The highlight of Arduino is its extremely easy-to-use application development
environment with a programming language that can be quickly learned, even by
beginners in electronics and programming. Arduino is widely used globally and is
increasingly proving its power through countless applications, unique systems of
open-source community users.
Arduino is open-source from hardware to software, with a very low cost. With a
small amount of money, users can own an Arduino board with 20 I/O ports that can
interact and control about that many devices. Arduino has strengths over other
microcontroller platforms, including:
- Runs on multiple platforms (programming can be done on different operating
systems, including Windows, Mac OS, Linux on desktop, and Android on
mobile).
- Simple and easy-to-understand programming language; open platform, as it
is developed based on open-source, allowing software to run on Arduino to
be easily integrated on different platforms; hardware expansion is easy, as
Arduino is designed and used as a module; it is simple, quick to assemble,
program and use the device; easy to share, as people can easily share source
code without worrying about the programming language or operating system
they are using. Arduino has many eye -catching applications, including 3D
printers, robots, UAVS, interactive games, lighting controls and high -speed
photography triggers.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 4

Arduino Uno R3 microcontroller board is one of the most popular committees in


the Arduino family. It was launched in 2011 and is the latest version of Arduino's
board. This kit circuit is based on the ATMEGA328P microcontroller to control and
operate the microcontroller. The United Nations Board is the first product in the
series of boards used by USB for communication.
Arduino has many notable applications, including 3D printers, robots, unmanned
aerial vehicles (UAVs), interactive games, light controls, and high-speed
photography triggers.
The Arduino UNO R3 microcontroller board is one of the most popular in the
Arduino family. It was introduced in 2011 and is the latest version 3 of the Arduino
board. This kit circuit is based on the ATmega328P microcontroller to control and
operate the microcontroller. The Uno board was the first product in the series of
boards that used USB for communication.

2.1.2 Arduino Uno R3 - Structure and Hardware:

About Arduino, Arduino Uno R3 is the most popular version of Arduino. The
United Nations version is a revised version 3 (R3), which is currently the latest
version. Compared with the old version of Arduino Uno, accuracy and durability
are much higher. Arduino Uno R3 is equipped with three types of 8 -bit AVR
microcontrollers, including Atmega8, Atmega168 and Atmega328.

Table 2-1 Specifications of Arduino Uno R3

Operating voltage 5V (USB)


Recommended operating voltage 6 to 9V
Number of digital I/O pins 14 pins ( 6 pins PWM)
Number of analog I/O pins 6 pins

Maximum output current per pin I/O 30 mA

Maximum output current (5V) 500 mA


Maximum output current (3.3V) 50 mA

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 5

32KB (ATmega328) with


Flash memory
0.5KB used by bootloader
SRAM 2 KB
EEPROM 1 KB
Operating frequency 16 MHz

2.1.3 Pinout diagram of Arduino Uno R3:

Figure 2-1 Pinout diagram of Arduino Uno R3

An Arduino Uno R3 board consists of 20 input and output pins, of which 6


function pins are PWM inputs and 6 function pins are PWM inputs.

2.1.4 Power supply:

Arduino Uno is powered with 5V through USB connection or external power


supply. The external power source (not from USB) can be obtained from AC-DC
converter module or battery pack.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 6

To connect with converter module, we can plug a 2.1mm center-positive plug


into the power jack on the board. When using battery pack, the pack is connected
between Vin and GND pins to supply power.
Arduino Uno can operate with external power source from 6 to 20V. If using
lower voltage, typically 7V, the 5V pin may supply less than 5V, but it may cause
unstable operation.
When using power source above 12V, the voltage regulator will become hot and
may get damaged, therefore it is recommended to use power source from 7 to 12V.
The energy pins are as follows:
 Vin (Voltage Input): is where external power source is supplied to
Arduino UNO (from 7V-12V), we can supply power through Vin pin
or via a power jack which is connected to this pin and the negative
pole of the supply is connected to the GND pin.
 GND (Ground): is the negative pole of the power supplied to Arduino
UNO. When we use devices with separate power sources, their
negative pins must be joined together.
 5V: is the output voltage supplied by Arduino UNO. The maximum
current allowed on this pin is 500mA.
 3.3V: is the output voltage of 3.3V. The maximum current allowed on
this pin is 50mA.
 IOREF (Input Output Reference): is the operating voltage of the
microcontroller on the Arduino UNO. It can be measured at this pin
and is 5V. However, it is not used to supply power from this pin.
 RESET: Pressing the Reset button on the board resets the
microcontroller. It corresponds to connecting the RESET pin to GND
via a resistor (10KΩ).
2.1.5 I/O Pins:
The Arduino UNO R3 kit has 14 digital pins that can be used as input or output
pins by using functions such as pinMode(), digitalRead(), and digitalWrite(). They

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 7

have only 2 voltage levels which are 0V and 5V, with a maximum input/output
current of 40mA on each pin. Each pin has pull-up resistors built into the
ATmega328 microcontroller (these resistors are not connected by default).
Some digital pins have special functions as follows:
 2 Serial pins: 0 (RX) and 1 (TX): used to send (TX) and receive (RX) TTL
Serial data. Arduino Uno can communicate with other devices via these pins.
Wireless serial connection, such as Bluetooth connection, is often referred to
as wireless Serial. If serial communication is not needed, it is not necessary
to use these pins.
 PWM (Pulse Width Modulation) pins (~): 3, 5, 6, 9, 10, and 11: these pins
allow you to output PWM with 8-bit resolution (values from 0 to 255
corresponding to the voltage range of the pin from 0V to 5V) using
analogWrite() function. In other words, you can adjust the output voltage of
this pin from 0V to 5V, instead of just fixing it at 0V and 5V like other pins.
 SPI (Serial Peripheral Interface) pins: 10 (SS), 11 (MOSI), 12 (MISO), 13
(SCK): In addition to their normal functions, these 4 pins are also used to
transmit data using the SPI protocol with other devices.
 LED 13: there is a orange LED (with "L" label) on the Arduino UNO board.
When you press the Reset button, you will see this LED flash as a signal. It
is connected to pin 13. When this pin is used by the user, the LED will be
turned on.
 Arduino UNO has 6 analog pins (A0 to A5) that provide 10-bit signal
resolution (0 to 210-1) to read voltage values ranging from 0V to 5V. With
the AREF pin on the board, you can provide a reference voltage when using
analog pins. That is, if you supply 2.5V to this pin, you can use the analog
pins to measure voltage values from 0V to 2.5V with a resolution of 10-bits.
Particularly, Arduino UNO has 2 A4 (SDA) and A5 (SCL) pins that support
I2C/TWI communication with other devices.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 8

2.2 Arduino IDE Software Overview:

Arduino IDE stands for 'Arduino Integrated Development Environment', which


is an open-source software environment primarily used to write code on a compiler
similar to C/C++ and load them into microcontroller boards.
The programming environment is simple and easy to use, the programming
language is easy to understand and based on the familiar C/C++ platform for
technical people. And importantly, the number of pre-written and shared code
libraries by the open community is incredibly large.

Figure 2-2 Interface of Arduino IDE 2.0.4

2.3 General about barcodes and scanners GM65:

2.3.1 Barcode concept:

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 9

Barcode (or also known as a barcode) is a method of storing and transmitting


information using a symbol called a barcode symbology. A barcode symbology or
simply barcode, is a symbol composed of a combination of straight bars and spaces
that represent patterns of characters, symbols, and numeric digits. Variations in the
widths of the bars and spaces represent data in the form of digits or characters that
can be read by a machine.
As an automatic identification technology, barcode allows for quick and
accurate data collection.

2.3.2 Common types of barcodes:

Around us there are many types of barcodes, the most commonly seen are 2
types of 1D and 2D codes.
2.3.2.1 1D barcode:

1D barcode (one-dimensional barcode) is a common linear barcode type,


consisting of alternating black and white parallel bars where data is encoded based
on the width (horizontal) of the bars. Each 1D barcode usually contains 20-25
characters of data. They are commonly used in retail and printed on packaging,
bags, boxes, etc. The commonly used types of 1D barcodes include:
- Universal Product Code (UPC): with parallel black bars encoded from an 11-
digit string (valid from 0 to 9) and a check digit at the end to create a
complete 12-digit barcode. It is used for labeling and checking consumer
goods at fixed points of sale worldwide. This barcode type is managed by the
US-based Uniform Code Council (UCC). Applications include retail,
supermarkets, consumer goods, etc.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 10

-
Figure 2-3 UPC barocde

- EAN (European Article Number): is an improvement of UPC-A barcode,


with the main difference being geographic application. Applications include
retail, supermarkets, consumer goods,....

Figure 2-4 EAN barcode

- Code 39: overcomes the biggest drawback of the above two barcodes, which
is the ability to encode an unlimited amount of data and a wider range of
characters, including uppercase letters, natural numbers, and some special
characters. Applications include Defense Department, healthcare,
administrative agencies, book publishing...

Figure 2-5 Code 39

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 11

- Code 128: is a highly rated and widely used barcode type due to its many
outstanding advantages: Compact barcode, stores a wide range of
information, and can encode more characters including uppercase letters,
lowercase letters, digits, standard ASCII characters, and control codes.
Applications include supply chain and logistics, retail supply chain,
manufacturing industry

Figure 2-6 Code 128

2.3.2.2 2D barcode:

2D barcode (also known as QR code) is a form of barcode that represents data


encoded in a matrix of small and large squares alternatively. The data in the 2D
barcode can be arranged horizontally or vertically, allowing it to store more
information than the 1D barcode. The 2D barcode can contain at least 2000
characters, and it's commonly used to link to websites or track products, identify
products, online payment, etc. The most common type of 2D barcode is QR Code
(Quick Response Code), which is widely used in advertising and branding,
product/service introduction, promotional campaigns, information retrieval, even
for scanning payment and money transfer at some banks.
- QR Code has many advantages, such as diverse sizes, fast data reading,
supporting 4 different data encoding modes (numeric, alphanumeric, byte,
Kanji), less error-prone, and especially, it's free to use.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 12

Figure 2-7 QR code

- Matrix code: This type of barcode is used for naming goods and documents.
Similar to QR Code, this barcode is rarely error-prone during use and has
fast reading capabilities..

Figure 2-8 Matrix code

- PDF417 barcode: PDF417 is a 2D barcode that is used in applications that


require storing massive amounts of data, such as digital images, fingerprints,
numbers, graphics, signatures, etc. This barcode is commonly used overseas.

Figure 2-9 PDF417 barcode

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 13

2.3.3 How Barcode works:

While you encounter barcodes on a daily basis, have you ever pondered how
they work? The following is how barcodes work:
- First, barcode scanners will beam light through the barcode and then into a
super-sensitive light detector using an incandescent light bulb or laser.
- The barcode's black lines absorb light, while the white elements of the
barcode show through and are reflected.
- The scanner measures the amount of light and converts it into computer-
readable data. For example, the light scanner records the black sections that
do not reflect well as 1 and the white parts as 0.
- On the system, inventory management software will receive and interpret
this information.

Figure 2-10 How barcodes work

2.3.4 Classification of barcode scanners and barcode recognition methods:

To read barcode symbols, people use a type of device called a barcode scanner,
which is essentially an optical reader that uses a beam of light or laser. Sometimes

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 14

when looking at a barcode symbol, we may see a series of numbers directly below
the barcode, while other times there may be nothing there.
This series of numbers is the encoded code that the barcode symbol represents.
The presence or absence of this number is due to the barcode printing software that
creates the barcode that can be recognized by human eyes. It is important only for
humans, not for machines since the machine cannot understand this number, but
only read the barcode symbols themselves - the black and white spaces.
There are two types of barcode readers classified according to the manufacturing
technology:
- Laser Barcode Reader.
- CCD Barcode Reader.
Since my system uses Laser Barcode Reader, I will focus on Laser Barcode
Reader.
2.3.4.1 Structure of Laser Barcode Reader:

Laser light is shone on the label surface and its reflection is captured by a sensor
(laser photo detector) to read a bar code.
A laser beam is reflected off a mirror and swept left and right to read a bar code
Using laser allows reading of distant and wide bar code labels.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 15

Figure 2-11 Structure of Laser Barcode Reader

The Laser Barcode Reader type consists of the following components: a laser
diode, a polygon mirror, a motor, and a light-receiving element (photodiode).
2.3.4.2 The principle of reading barcodes:

Figure 2-12 The principle of reading barcodes

(1) The laser beam emitted from the laser diode is aimed at the barcode via the
polygon mirror. The light-receiving element (photodiode) receives the reflected
light from the barcode.

(2) This reflected light is in the form of an analog wave.

(3) The barcode reader converts the analog waveform to digital (A/D conversion)
and determines the width of the bars and spaces using the digital signal.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 16

(4) The barcode reader decodes the combination of bars and spaces into barcode
data. The decoded data output is transmitted to an external device via RS232C or
equivalent communication.

The advantages of laser barcode scanners are their high sensitivity, precision,
ability to scan on curved surfaces, and long-range scanning capabilities. The
downside is that they are not as durable as CCD scanners because laser scanners use
a laser eye similar to the read head of a disc. After reading for a limited time, the
laser eye can become weak, resulting in the "barcode sticking" effect, similar to the
disc sticking effect of a read head, and it can also be permanently damaged..

2.4 Servo DC motor overview:

2.4.1 What is a servo motor?

A servo motor is a type of electric motor that can rotate with great precision.
Normally this type of motor consists of a control circuit that provides feedback on
the current position of the motor shaft, this feedback allows the servo motors to
rotate when regulated (by PWM pulses) with a rotation angle ranging from 0 0 to
1800.
Servo motors can be characterized according the motor controlled by
servomechanism. If motor is powered by a DC power supply then it is called DC
servo motor, and if it is AC-powered motor then it is called AC servo motor.
Servomechanism is basically a closed-loop system, consisting of a controlled
device, controller, output sensor and feedback system. The term servomechanism
most probably applies to the systems where position and speed is to be controlled.

2.4.2 Working principle of servo motor:

Servo motors are utilized to precisely control both position and speed, although
in simple cases, only position may be controlled. A potentiometer coupled with the
motor shaft through gears senses the mechanical position of the shaft, and converts
it into an electrical signal that is compared to the command input signal. In

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 17

contemporary servo motors, electronic encoders or sensors are alternatively used to


detect the position of the shaft.
Command input is provided based on the required position of the shaft. When
feedback signal varies from the input signal, an error signal is produced. This error
signal is then amplified and delivered as input to the motor, causing rotation. When
the shaft attains the desired position, the error signal becomes zero and the motor
halts, holding the position.
The PWM (Pulse Width Modulation) principle governs the operation of a servo
motor, wherein the angle of rotation is controlled by the duration of the applied
pulse to its Control PIN. Servo motors are essentially composed of a DC motor that
is regulated by a variable resistor (potentiometer) and some gears.
A pulse is delivered every 20 milliseconds, with the pulse width dictating the
position of the shaft. For example, a 1ms pulse will turn the shaft anticlockwise by -
90°, a 1.5ms pulse will place the shaft in the neutral position at 0°, and a 2ms pulse
will turn the shaft clockwise by +90°.

Figure 2-13 Working principle of servo motor

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 18

2.5 Operating principle of infrared sensors:

Active infrared sensors use radar technology to transmit and receive infrared
radiation. This radiation strikes surrounding objects and bounces back to the
device's receiver. This technique allows the sensor to detect not just movement in an
area, but also how distant the item is from the instrument.
Operating principle:
Infrared sensors function in a similar way to object detection sensors. These
sensors comprise an IR LED (infrared light-emitting diode) and an infrared
photodiode. The IR LED is a type of transmitter that emits infrared radiation. The
photodiode receiver mainly detects the radiation using an IR transmitter. These
photodiode receivers are available in the form of optical diodes.
When the IR emitter produces radiation, it reaches the object and some of the
radiation is then reflected back to the IR receiver. The output of the sensor can be
determined by the IR receiver depending on the intensity of the reflection.

Figure 2-14 Operating principle of infrared sensors

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 19

CHAPTER 3: DESIGN AND CONSTRUCTION

3.1 The block diagram of the system:

MOTOR CODE SCANNING


BLOCK BLOCK

POWER DISPLAY
BLOCK PROCESSING BLOCK
BLOCK

SENSOR MOTOR
BLOCK BLOCK

Figure 3-15 The block diagram of the system

3.1.1 Power Block:


The power supply block uses a 12V - 3A adapter to power the motor block
(conveyor) and through the voltage regulator circuit to power the servo motor,
Arduino Uno R3, sensor block, and LCD screen.
The main components to form the voltage regulator circuit are a diode capacitor
(220μF) and two types of ICs, 7809 and 7805. Both 7809 and 7805 are fixed output
voltage regulator ICs with 9V and 5V, respectively. Both belong to the LM78xx
series of positive voltage regulator ICs, which are produced in the TO-220 package.
These ICs are commonly used in commercial electronic circuits and devices.
The structure and pins of these two types of ICs are the same, differing only in
their technical specifications:

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 20

Figure 3-16 Specifications of IC 7805


Table 3-2 specifications

Datasheet 7809 7805


Pins 3 3
Voltage output 9v 5V
Voltage input 12V to 24V DC 7V to
18VDC
Output current 1A 1A
Operating temperature 0°C to 125°C 0°C to 125°C
Maximum power 9W 5W

The power block will provide 12V for the conveyor motor, 9V for the
processing block, 5V for the code scanning block, the Servo motor block and the
sensor block.

Figure 3-17 Power Block diagram

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 21

3.1.2 Code Scan Block:

The GM65 barcode reader module, is supplied with 5V, used to identify
barcodes to give information to the microprocessor block.
The GM65 barcode reader module is a high-performance scanner that can read
1D and 2D barcodes quickly. It also has a fast scan speed for linear codes, as well as
barcodes on paper or screen.
The GM65 barcode reader module is a powerful bar code decoding algorithm
based on image recognition that can simply and reliably scan bar codes while
simplifying secondary development. The GM65 barcode reader module operates
reliably in low-light conditions and throughout a wide temperature range.

Figure 3-18 The GM65 barcode reader module

Table 3-3 Specifications of GM65 barcode reader module

Model GM65 - Barcode Scanner


(1D): EAN- 8, EAN-13, UPC-A, UPC-E, Code 39, Code 93,
Code 128, EAN128, Codebar, industrial 2 of 5, Interleave 2 of 5,
Decoding Ability
Matrix 2 of 5, MSI, postal code, …
(2D): PDF417, QR Code , Data Matrix
Interface USB2.0 ;UART
Resolution 0.10mm (4mil)
Operating Voltage 5V
Operating Current 120 mA

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 22

Type of Illuminant 617nm LED(Aimer), 6500K LEDs(Illumination)


Buzzer and bi-color light: Red-power, Blue-decoding
LED Indicator
Successfully
Scan Angle Roll:0-360°, Pitch:±65°or greater, Yaw:±60°or greater
Scanning angle
34°, Elevation angle 26°
Inclination angle
Print Contrast 30% minimum reflective difference
Reading Distance 25 - 250mm
Operating Temperature -20 degrees to 55 degrees
Storage Temperature -40 degrees to 65 degrees
Temperature Humidity 5% to 95% Relative humidity, Non-condensing

Function of GM65 barcode reader module:


The special thing here is that the GM65 barcode reader module can scan almost
all types of barcodes such as:
 Barcode type (1D): UPC/EAN, UPC/EAN with supplementals,
BooklandEAN, ISSN, UCC Coupon Extended Code, Code 128, GS1-128,
ISBT 128, Code 39, Code 39 Full ASCII, Trioptic Code 39, Code 32, Code
93, Code 11, Matrix 2 of 5, Interleaved 2 of 5, Discrete 2 of 5, Codabar,
MSI, Chinese 2 of 5, GS1 DataBar variants, Korean 3 of 5, ISBT Concat
 The QR code type (2D) : QR Code , PDF417, Data Matrix
The GM65 module can load code or change functions by scanning QR codes in
the device catalog, such as communication interface, read mode, read area, lighting
and collimation, prompts, date edition, etc.
The scanning module is connected to the processing and power supply block
through the UART port as follows: The 5V pin is connected to the 5V power
supply, the GND pin is connected to the GND pin, the TX is connected to digital
port 7, and the RX is connected to digital port 6 of the processing block..

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 23

3.1.3 Processing block:

Use the Atmega368 chip from the Arduino board to receive the code, process
the information from the code scan block to control the sensor block, servo motor
block, and display block.

Figure 3-19 Processing Block

3.1.4 Sensor Block:


The infrared sensor, supplied with 5V, is used to identify when there is an
obstacle and transmit the signal to the Arduino block to process. Using infrared
sensors with the advantage of low cost, less power can detect motion in conditions
with or without light with equal reliability and without contact with the subject.

Figure 3-20 Infrared sensor

Structure:

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 24

- Infrared LED: This is a device that emits infrared light from a light source.
- Infrared detector: This is a device that receives signals and detects infrared
radiation that is reflected back.
- Resistor: This is a device that limits the current flow to prevent the LED
from operating at too high a current and causing the system to malfunction.
- Wire: The main function of the wire is to connect the components to create a
stable operating sensor.

Figure 3-21 Wiring diagram for sensors

3.1.5 Motor Block:


The servo motor receives the signal from the processing unit to perform the task,
rotates to push the product. The motor that the system uses is a compact and
reasonably priced sg90 servo motor.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 25

Figure 3-22 Servo motor

Specifications:
- Operating voltage: 4.8V ~ 6V DC
- Rotation speed: 0.12 sec/60° (4.8V) or 0.1 sec/60° (6 V)
- Torque: 1.8kg/cm (4.8 V), 2.5kg/cm (6 V)
- Rotation angle: 180°
- Dimensions: 22.5/ 11.8 / 30 mm
- Power cord length: 175mm
- Weight: 9g
- Operating temperature: 0°C to 55°C
SG90 Servo wiring to the processor:
Brown (GND) to GND source
Red (VCC) to 4.8V - 6V
Yellow (Signal) to pin PWM

Figure 3-23 Wiring diagram of servo motors

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 26

3.1.6 Display block:


LCD (Liquid Crystal Display) display devices will receive signals from the
processing block and output the results to the screen according to system
requirements.
LCD (Liquid Crystal Display) display devices are now employed in numerous
microcontroller applications. LCD offers several benefits over other display forms,
including: It can show a variety of characters, is simple to integrate into application
circuits using a variety of communication protocols, requires very few system
resources, and is inexpensive...

Figure 3-24 LCD Screeen

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 27

Table 3-4 Specifications of LCD

Pin Name Pin Description Pin Connection

This is a ground pin


VSS Connected to the ground of the power source
of LCD

This is the supply


VCC Connected to the power source
voltage pin of LCD

Adjusts the contrast Connected to a variable resistor that can source


V0/VEE
of the LCD. 0 to 5V

Connected to a microcontroller pin and gets


Toggles between
Register Select either 0 or 1.
Command/Data
(RS) RS=0: command mode
Register
RS=1: data mode

Connected to a microcontroller pin and gets


Toggles the LCD
Read/Write either 0 or 1.
between Read/Write
(RW) RW=0: write operation
Operation
RW=1: read operation

Must be held high to


Connected to microcontroller and always held
Enable ( E) perform Read/Write
high.
Operation

+ 8-bit mode: Data is transmitted on all 8 lines,


Pins used to send
Data Bits (D0- with the MSB bit being the DB7 bit.
command or data to
D7) + 4-bit mode: Data is transmitted on 4 lines from
the LCD.
DB4 to DB7, MSB bit is DB7

LED background
LED Positive (A) Connected to +5V
anode

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 28

LED Negative LED background


Connected to ground
(K) cathode

To connect the LCD to Arduino using 4-bit mode, we need 11 pins on the
Arduino, and if we want to use the full capacity of the LCD, we need 15 pins on the
Arduino, but using 4-bit mode is still more efficient.
We need to supply positive voltage (+) to the VDD pin of the LCD and negative
voltage (-) to the VSS pin.
Connect the Baclight Anode pin to the positive voltage (+) and the Backlight
Cathode pin to the negative voltage (-) to control the screen backlight.
Connect the VEE pin to a potentiometer to adjust the screen brightness.
Connect the R/W pin to GND (R/W=0) to write data to the LCD.
Connect the RS and Enable pins to the Arduino board to communicate with the
Arduino.
To control the LCD in 4-bit mode, connect pins D4, D5, D6, and D7 to the
Arduino board.

Figure 3-25 Wiring diagram of LCD with arduino

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 29

3.2 General principle diagram:

Using proteus software to simulate the schematic diagram of the system:

Figure 3-26 General principle diagram

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 30

CHAPTER 4: PROCEED TO IMPLEMENT

4.1 System operation:

The system uses barcode scanning of various types, from 1D to 2D, as requested
by the user to classify three products called products A, B, and C (or defective
products). The system is powered and the conveyor belt will run continuously.
When product A passes through the system, the barcode recognition signal will be
transmitted to the processor and allows the infrared sensor for product A to be
activated when the product passes through the sensor area. The signal from the
sensor will be transmitted back to the processor, and at the same time, the processor
will activate the servo motor angle control and push the product down.
Similarly, for product B, the operation is similar to product A, but even though
the sensor and servo A are positioned before the sensor and servo B, the signal from
the processor only allows sensor and servo B to operate.
Finally, product C (or defective product) will not activate the two sensor and
servo systems but will only be brought to the end of the conveyor belt.
Each time the motor pushes the product, the system will count the number of
times it pushes, which is equivalent to the number of products. However, product C
(or defective product) will be counted when the barcode recognition system
identifies it. Based on the information provided by the processor, the display will
show the barcode name and the number of products classified.
Additionally, the system has a data reset function when the system is turned off
or when the "Reset" barcode is scanned by the scanning system.

4.2 Algorithm flowchart of the system:

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 31

Figure 4-27 Algorithm flowchart of the system

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 32

CHAPTER 5: EXPERIMENT

5.1 Experimental process:

5.1.1 Designing printed circuit:

Step 1: We proceed to sketch the schematic diagram of the system on Proteus


software, determining the appropriate voltage to supply each component.

Figure 5-28 PCB circuit

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 33

Step 2: From the schematic diagram on Proteus software, we design the


component library, arrange and draw reasonable wires to have the following circuit
board:

5.1.2 Printed circuit construction:

Step 1: We print the circuit we designed on one-sided glossy paper (tracing


paper). The next step is to heat the paper to transfer all the ink onto the copper
board.

Figure 5-29 Printing circuit into paper

Step 2: After the copper board has all the circuit traces, we immerse it in an
etching solution.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 34

Step 3: After the solution is finished, we take out the board, wash and remove
the ink, and there will be copper traces left on the board, like the circuit we
designed on the software.
Step 4: Drill and solder components to have a complete circuit board.

Figure 5-30 Complete printed circuit

Step 5: Attach the component pins to the circuit

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 35

Figure 5-31 Circuit after attaching component pins

5.1.3 Load the program and run the printed circuit:

Connect the Arduino board to the computer using the USB port to load the
program through the Arduino IDE software.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 36

After loading, we attach the Arduino board to the printed circuit, supply 12V
power to the circuit
When the power is turned on, the LCD will light up and show "Classification
system".

Figure 5-32 LCD displays

At this time, the GM65 scanner lights up and waits to scan


The scanner operates when a barcode is passed and transmits data to the
processor.
The detection sensor and the servo work normally.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 37

Figure 5-33 Completed system

5.2 Experimental results:

After providing a 12V- 3A power supply to the system, the conveyor belt motor
and the GM65 scanner light up. The LCD screen lights up and displays
"Classification system" after 4 seconds, and then transitions to display "by
MinhPhat" and "420H0264" after 2 second it displays"ID:".
When a product with a barcode passes through the scanner, the GM65 scanner
transmits the barcode data to the processing unit for operation. Product A passes
through sensor 1, triggering servo motor 1 to move and push product A to its
container. After 6 seconds, servo motor 1 returns to its normal state. The same
process applies for product B. Product B passes through sensor 1 but only activates
when sensor 2 recognizes it, triggering servo motor 2 to move. The LCD display
shows the count of detected products.
When products with barcodes other than product A and B are detected, all
sensors and servo motors remain inactive and are moved to the end of the conveyor
belt. Notably, when a barcode with the data "Reset" is detected, the LCD displays
"Reset" and the processing unit restarts the counting process from the beginning.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 38

5.3 Experimental conclusions:

Based on the expected results in Chapter 1:


- The system has successfully classified the proposed product types.
- The scanning system is stable but requires adjustments to the scanning speed.
- The sensors and servo motors only operate when the correct product has
been set.
- The display screen shows the barcode and the number of products classified
as required by the system.
- However, the display screen sometimes flickers and the displayed
information is scramble.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 39

CHAPTER 6: CONCLUSION

6.1 Advantages:

- High degree of accuracy based on barcode information.


- Designed with easy expansion and repair in mind, the system allows for
effortless addition of features and upgrading of hardware.
- The barcode scanner can be configured according to individual needs
- The product data can be edited by reloading the data with specialized
software.
- Automates the sorting process, improving efficiency and accuracy.
- Fast reading and processing speeds, saving time in the sorting process.
- Easy to manage the quantity of products.
- Energy-efficient.

6.2 Disadvantages:

- The system is rudimentary and the conveyor belt width is only suitable for
small products intended for personal use.
- The conveyor belt operates continuously and can only be turned off using a
switch.
- The scanning system is at a fixed location and distance, and products must be
placed in the correct position for scanning to occur.
- The proximity sensors have a close range.
- The servo motor force can only push small products.

6.3 Direction of development:

- Develop more overload relay system when there is overload, warning


speaker.
- The system will be able to develop more self-regulating conveyor motor on
and off.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 40

- Barcode reading speed and reliability can be improved by using higher-end


GM65 modules or combining with advanced vision technology that employs
cameras to recognize the products.
- Utilizing wireless interfaces such as Bluetooth, WiFi, Zigbee; barcode
information from Arduino can be sent to computers or smartphones,
promoting connectivity and data transmission.
- The conveyor can be changed or expanded to classify a wider range and
larger quantity of products and esign more sensors, servo motors to classify
more products.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 41

REFERENCES

English:
Banzi, M. a. (2022). Getting started with Arduino. Abuja, Nigeria: Maker Media.
Debashis Das. (2022, March 16). Arduino IR Sensor Tutorial - Interfacing IR
Sensor Module with Arduino Uno. Retrieved April 11, 2023, from Circuit
Digest: https://circuitdigest.com/microcontroller-projects/interfacing-ir-
sensor-module-with-arduino
Dejan. (2020). Arduino LCD Tutorial | How To Connect an LCD to Arduino.
Retrieved April 09, 2023, from How To Mechatronics:
https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/
GM65-S Bar Code Reader Module User Manual. (2020, June 12). Retrieved April
18, 2023, from Banggood:
http://myosuploads3.banggood.com/products/20200612/20200612015539G
M65-SBarcodereadermuduleUserManual.pdf
Panicker, R. C. (2021, January 29). Servo Motors. Retrieved April 10, 2023, from
Servo Motors - Arduino:
https://wiki.nus.edu.sg/display/Arduino/Servo+Motors
Raj, A. (2015, August 1). Servo Motor Basics, Working Principle & Theory.
Retrieved April 10, 2023, from Circuit Digest:
https://circuitdigest.com/article/servo-motor-working-and-basics
SAWICZ, D. (n.d.). Hobby Servo Fundamentals. Retrieved April 10, 2023, from
Hobby Servo Fundamentals:
http://www.princeton.edu/~mae412/TEXT/NTRAK2002/292-302.pdf
Schadt, M. (1997). Liquid crystal materials and liquid crystal displays (Vol. 27).
Annual review of materials science.

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 42

Vietnamese:
Việt, Hồ Mậu, and Dương Thị Quy. (2022, 08). NGHIÊN CỨU XÂY DỰNG HỆ
THỐNG PHÂN LOẠI SẢN PHẨM TỰ ĐỘNG THEO MÃ VẠCH DỰA TRÊN
NỀN TẢNG LABVIEW. Retrieved April 18, 2023, from BẢN TIN KHOA
HỌC VÀ GIÁO DỤC:
https://tckhyersin.edu.vn/Data/Upload/MagazineArticle/4/8.%20L%C3%AA
%20Ho%C3%A0ng%20Hi%E1%BB%87p.pdf
Điều khiển LCD1602 bằng Arduino UNO | Cộng đồng Arduino Việt Nam. (2015,
November 10). Retrieved April 18, 2023, from Arduino.vn:
http://arduino.vn/bai-viet/531-dieu-khien-lcd-bang-arduino-uno

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 43

APPENDIX

#include <SoftwareSerial.h> // Declare to use SoftwareSerial library on Arduino,


allowing to control serial communications (UART) via digitals pins of Arduino
board, instead of RX/TX pins.
#include <Servo.h> //declare the servo library
#include <LiquidCrystal.h> //declare the LiquidCrystal library, provides functions
to control LCD (Liquid Crystal Display)

int spA=0; // format the quantity of product A to 0


int spB=0; // format the quantity of product B to 0
int other=0; // format number of other defective product to 0

SoftwareSerial GM65(7,6); //connect TX,RX to digital pins 7 and 6 of


Arduino
LiquidCrystal lcd (13,12,8.9,10,11); //(rs,en,d4,d5,d6,d7) connect to pins
13.12,8,9,10,11 of Arduino
Servo myServo1; // the variable representing the Servo is connected to
a control pin on the Arduino board
Servo myServo2; // the variable representing the Servo is connected to a
control pin on the Arduino board

#define sensor_A_pin 2 //attach sensor A pin value to Arduino pin 2


#define sensor_B_pin 3//attach sensor B's value to Arduino's digital pin 3

#define servo1_pin 4 //attach the value of pin servo1 to the value of pin 4 of the
Arduino

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 44

#define servo2_pin 5//attach the value of pin servo2 to the value of pin 5 of the
Arduino

void setup() {
Serial.begin(9600); //initialize and configure serial port (UART) for
communication between Arduino and other devices
GM65.begin(9600); //initialize communication speed with barcode scanner GM65
lcd.begin(16,2); // Initialize LCD

pinMode(sensor_A_pin, INPUT);
pinMode(sensor_B_pin, INPUT);

myServo1.attach(servo1_pin); // attach the servo motor to the SERVO_PIN . pin


myServo2.attach(servo2_pin); // attach the servo motor to the SERVO_PIN . pin

myServo1.write(180); //send signal to Servo motor1 rotated at 180


myServo2.write(180); //send signal to Servo motor2 rotated at 180

lcd.setCursor(2,0); // command to move the cursor to the position at row 0, column


2
lcd.print("Classification"); // Output "Classification" data to LCD screen
lcd.setCursor(4,1); // command to move the cursor to the position placed at row 1,
column 4
lcd.print("System"); // Output "System" data to LCD screen
delay(4000); // 4 seconds late

lcd.clear();

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 45

lcd.setCursor(2,0); // command to move the cursor to the position at row 0, column


2
lcd.print("by MinhPhat"); // Output data "by MinhPhat" to LCD screen
lcd.setCursor(3,1); // command to move the cursor to the position placed at row 1,
column 3
lcd.print("420H0264"); // Output data "420H0264" to LCD screen
delay(2000); // 4 seconds late
lcd.clear(); // command to delete all content displayed on the LCD screen and
return the cursor to the original position of column 0, row 0
}
void loop() {
lcd.setCursor(1,0);
lcd.print("ID:");

if (GM65.available()) //command to check if any data has been sent to the GM65
module
{
String code = GM65.readStringUntil('\n'); //assign the code variable with the data
read from the code scan block
Serial.println("ID:"+code); //

if(code.indexOf("5011451103856")!= -1 && code.length()==14)


//if there is a string "5011451103856" contained in the code variable and length
=14
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("ID:");
lcd.setCursor(4,0);

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 46

lcd.print(code); //Export product code A


lcd.setCursor(0,1);
lcd.print("SPA:");

while(digitalRead(sensor_A_pin)==1)
//while sensor A has signal level 1 ie there is no obstacle, servo 1 is still at
180 . angle
{
myServo1.write(180);
}

delay(1000);
myServo1.write(45); //servo1 rotates a 45 . angle
Serial.println("spA");
Serial.println(" ");
delay(6000); //6 seconds late

myServo1.write(180); //return to original angle

spA++; //plus 1 product A has been removed


lcd.setCursor(7,1);
lcd.print(spA); //Output the number of products A

}
else if(code.indexOf("3337875546430")!= -1 && code.length()==14)
//if there is string "3337875546430" contained in variable code and length =14
{
lcd.clear();
lcd.setCursor(1,0);

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 47

lcd.print("ID:");
lcd.setCursor(4,0);
lcd.print(code);
lcd.setCursor(0,1);
lcd.print("SPB:");

while(digitalRead(sensor_B_pin)==1)
{
myServo2.write(180);
}
delay(1000);
myServo2.write(45);

Serial.println("spB");
Serial.println(" ");
delay(6000);
myServo2.write(180);
spB++; //Export the number of products B
lcd.setCursor(7,1);
lcd.print(spB);
}
else if(code.indexOf("reset")!= -1 && code.length()==6)
//if there is a string "reset" contained in the variable code and length =6
{
lcd.clear();
lcd.setCursor(6,0);
lcd.print("Reset");
spA=0; //restore quantity values
spB=0;

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM
PROJECT OF EMBEDDED SYSTEM
PAGE 48

other=0;
delay(4000);
lcd.clear();
}
else
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("ID:");
lcd.setCursor(4,0);
lcd.print(code);

other++; //Add 1 value of other product quantity


Serial.println("Other");
lcd.setCursor(0,1);
lcd.print("Other:");
lcd.setCursor(7,1);
lcd.print(other);
}
}
}

THE BARCODE-BASED PRODUCT


CLASSIFICATION SYSTEM

You might also like