Internet of Things Based Smart Vending Machine using Digital Payment System

ABSTRACT


INTRODUCTION
The Internet of Things (IoT) incorporates various devices into networks to offer progressed and intelligent services. The concept of intelligent gadgets, smart homes, smart cities and so on, the Internet of Things (IoT) has risen as a region of unfathomable effect, potential, and development, with Cisco Inc. foreseeing by 2020, the approximate number of intelligent devices will be 50 billion in the market. The present organizations mean to enhance customer engagement by thinking of different business models and promoting strategies as innovation keeps on developing at tumultuous speeds. The fourth industrial revolution and the expanding reception of the IoT have transformed current corporate strategies. Actualizing sensors in existing  ISSN:2089-3272 IJEEI, Vol.9, No. 3, September 2021: 719 -731 720 merchandise update them to an object. This system is fit for getting a response from its atmosphere through sensing with other devices and fine-tuning its behaviour consequently, at the end of the day, a cyber-physical system (CPS) [1][2][3][4]. Big data analytics methods have also been remembered for the critical purposes of the present organizations, be that as it may, a few deterrents and restrictions have restricted their amalgamation in rehearsal. Present big data analytics procedures should be improved to manage the ever-expanding utilization of speed and veracity of captured data [5,6].
The vending machine is essentially an IoT-enabled automated machine that dispenses items like drinks, snacks, foods and so forth. The vending machine can assist shopkeepers with reducing their expenses by paying a lower rental charge with 24 hours of working time each day, thereby maximizing their profit margin. A customer can buy products easily with the help of digital payment systems through the vending machine. Vending machines are extensively and frequently used in many technologically advanced nations like the USA, UK, China, Japan and more [7][8][9][10].
Vending machine business is an exceedingly divided and competitive business with many small and medium ventures per country and only two or three multinational organizations. Without a doubt, the vending margins are not very high to the point that any interest in trend-setting innovations bringing operational cost investment funds expects high legitimize the Return on Investment (ROI). In this manner, small vending operators are ordinarily reluctant to put resources into new advances [11][12][13].
With the immense importance of vending machines, this paper presented a locker-based smart vending machine connected to the Internet that is implemented with IoT technology, which will allow customers to buy any product 24/7 and be cost-effective. It includes features digital platform on the web for the vendors, refillers and admins to operate and track the business on a fingertip. As digital payment systems are prevalent nowadays and commenced a new potentiality of payment methods, the developed smart vending machine is locker-based, and customers can buy products by making payments using their digital payment wallet with the help of a mobile application. The prime objective of our methodology is to diminish the overall cost of the business and make this model suitable to draw in a more significant number of vending machine operators that could apply this innovation, simultaneously improve the customer buying experience. The domain of the system is very narrow. [16] Focuses on pollution prevention caused due to plastic items Reverse vending machine based pollution management system Focus only on environmental issues like pollution. [17] Focuses on Designing Human Mistake-Free Machine Human-centred design process Try to design a human involvement-free system.
From Table 1, it is observed that none of the papers focuses on mobile banking payment systems. Our system developed an IoT-based smart vending machine where customers can make payments using their mobile phones.

RESEARCH METHOD
The main goal of our research is to empower a cost-effective platform for vending machine business with the assistance of the state of the art technology and IoT solutions. Figure 1 depicts the underlying highlevel scenario (SCN) amongst the key different components and users.

SCN-1
Customers will be connected to the Internet in their smartphones provided by the Mobile Network.

SCN-2
Each vending machine has a unique QR code (Quick Response code) printed to its body, containing a specific URL connected to a web-based system that gives a virtual representation name Virtual Vending Machine to the customer. In this way, the client can see the list of products of that particular vending machine and select the items to purchase the items from the machine.

SCN-3
A mobile application has been developed to interact with the Virtual Vending Machine, which needs to be installed in the customer's smartphone. It comes up with the advantage of enabling greater security in payment from the user's wallet and provides a comfortable user experience to the customer to interact with the machine to purchase the product.

SCN-4
An IoT Gateway is installed inside the physical vending device and connected through the Internet. This built-in electronic board is designed and assembled with Arduino compatible modules with meagre costs. After completing a successful payment, the machine gets the request to dispense the item in the locker.

SCN-5
Digital Payment Service receives the customer payment that has been paid through the app. On the Internet of Things-based vending machine, mobile proximity payment can be applied using a smartphone app in a fully contactless way [18].

SCN-6
The payment goes to the Merchant Account legitimately after deducting a particular percentage as a commission that the vending machine operator agreed to receive from the merchant.

IMPLEMENTATION
In our proposed framework, a user has to install a mobile application that we have developed to communicate with the vending machine. Through this application, a customer needs to sign in by giving a mobile number. For the first time, a customer needs to verify the account by providing a verification number that has been generated and sent by the system to the customer's mobile number. After the successful login customer needs to scan the printed QR code in the machine; if the internet connection is available on the customer's phone, the list of products with the price of the particular machine will be displayed in the app. Customers can choose the products and make the payment through their Digital Payment Service account integrated with the mobile app. In this system, we used bKash, a top-rated Bangladeshi digital payment service, for the simulation [19]. After a successful transaction, the products will be dispensed from the lockers for collection.
The way toward buying items in our framework is straightforward, and it tends to be finished in three stages, as shown in figure 2.

How it works:
▪ Scan the QR code printed on the vending machine. ▪ Choose the product and pay through a digital payment account. ▪ Collect the purchased item. Figure 3(a) demonstrates the UI for the client where they need to tap the "Scan QR Code' button to scan the imprinted QR code on the vending machine body. Figure 3(b) shows that the client will navigate to the item list screen if the scan is successfully done.  Figure 4(a) shows the lists of the products available with the price and picture of the vending machine's products. Customers can pick up to 5 items maximum to purchase at one go. The selected items will be shown up in the cart below the screen, along with the total price of picked items. Customers can discard anything from the cart as they need. When a user can continue by tapping the arrow icon in the right corner of the cart, it will navigate the customer to the checkout screen, where the client will see the list of the products he has picked, as appeared in figure 4(b). Customers can even now discard any item from the list subject to their tendency. These features are giving a decent user experience in terms of purchasing items from the vending machine. By tapping the "Buy with bKash" button down, the customer will continue to make the payment through the bKash payment system. Ensuing to pick things customers need to pay by bKash by utilizing their bKash credentials is shown in figure 5.

The Process of the payment is saved and issued using real money.
To make a successful payment, customers must have a sufficient balance in their bKash wallet and provide a valid bKash PIN. Once the payment is successful, the amount issued for the purchased items will be deducted from the customer's bkash wallet, which is entirely handled by a digital payment company (bKash). All the necessary information of payment, such as items, number of items, customer, transaction id, etc., are saved in the database as payment history, which is helpful to track the payment and manage the inventory.

Collection of Products
After a successful transaction with bKash, the system will communicate with the vending machine through the IoT-enabled API. The API will update the status of the LED in the database, indicating the vending machine lockers are open or not. The hardware will anticipate the database persistently to check the update. With the objective, it will choose to turn on the specific LED's, which represents the locker we utilized in our simulation. The system will check the number of items and which items are picked, and according to that the locker will automatically open and dispense the products to the customer. In any exceptional cases, for instance, no locker opened a lot after a successful transaction, the wrong item is passed on or expired items are conveyed, etc., or some other bothersome conditions happened, there will be a report and contact segment for the customer in the app with the objective that they can inform about the bungle or blunder cases to the vendor.

Cloud System Architecture
A cloud-based distributed system can be the solution for maintaining a few machines for many of them. As an outcome, the size of the vending operators, estimated in the number of machines to be connected, ought not to be a hindrance to utilizing the solution at all. Vending machine operators can own multiple vending machines and operate their business in real-time [20,21].  Figure 6 describes the building blocks of the architecture of the software application that has been designed. This high-level diagram depicts the relationship between the components and the scenarios (SCN) of their interactions. It also shows the three primary services of the system are Application, API and Data Storage, where Application and API together play a role as one block.
The web application has three types of users. Customers are passive users of the system. In SCN-1, the mobile customer application interacts with the web application through the API provided by the web system. Customers can create accounts using OTP (one-time-password) verification code in the system and get the list of the product of the intended vending machine. Also, the web application can store the user payment information to give a seamless experience to the customer while purchasing. This web application bridges the digital payment system and the customer application enabling all the business logic and securities.  Our system uses Laravel (an open-source PHP framework) to write the program and developed RESTful API to communicate users and IoT modules. The web application provides an API to access the database to the IoT module as SCN-5 to know which and when the locker should open and close to dispense products. SCN-6 represents the link between web applications and the database. The SCN-7 IoT module receives the data from the web application through the API.
In short, designing our private application allows us to execute self-provisioning systems to facilitate day-to-day tasks, customize the feature according to the demand, and add to our target, making vending machine business very cost-effective.

Cloud System Security
It is imperative to maintain proper service when we primarily use web or cloud services. The analyses of security from the various perspectives for sales points like vending machines are crucial [22,23]. The security measures taken for developing the system has been described below: i. Users authorization: The credentials of vendors and admins are encrypted into the web application. Advanced Encryption Standard-256 (AES-256) algorithm has been used to store the user's password in the server.
ii. Customer authorization: OTP (one-time-password) system is utilized to do not have to store the much data of the customer to authenticate into the mobile application. Each time the customer will pay out a buy, they have to provide a digital payment PIN (Personal Identification Number). The benefit of this mechanism is that if the cell phone is undermined, the aggressor can get into the application yet can't make any payment and personal information.

Process of security applied for this whole system, as it is using cashless payment
i. Digital payments: As our system uses the secure digital payment API of bKash, the security measures of cashless digital payment are almost dealt with by the company. Therefore, as long as the user is authorized and uses the personal account, the payment is highly secure. ii. Secure Web communications: included SSL (Secure Socket Layer) in the system so that our web application uses HTTPS to make sure the data traded on the web are secured.

Hardware Prototype
Arduino-based electronic components have been chosen to build our hardware prototype to interact with the Vending Machine Controller. It obliges to send acknowledgement messages to the vending machine controller every 200ms. Figure 11 is the block diagram of the vending machine hardware prototype that shows how all the hardware components have been integrated. Figure 11. Block Diagram of Hardware Prototype

ATmega 2560 Microcontroller
The ATmega2560, as shown in figure 12, is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. It contains a chip central processing unit (CPU), Random access memory (RAM), Read-only memory (ROM), I/O unit, interrupts controller and so forth. In this manner, a microcontroller is utilized for rapid signal processing operation inside an embedded system [24].

Esp8266 Wi-fi module
The ESP8266 is a low-cost WI-FI microchip, with the capability of a full TCP/IP stack and microcontroller, as shown in figure 13. This module permits microcontrollers to associate with a wi-fi system and make essential TCP/IP connections [25].

Light-emitting diode (LED)
A light-emitting diode (LED) in figure 14 is a semiconductor light source that emanates light when electricity flows through it. Electrons in the semiconductor recombine with electron openings, discharging energy as photons. The shade of the light is controlled by the energy required for electrons to cross the band hole semiconductor [26]. Figure 14. Light-emitting Diode Figure 15 shows that ATmega 2560 is used, which operates at 16 MHZ frequency, 256KB flash, 8KB RAM is the master microcontroller (MCU), or the brain of the whole system peripherals are connected to it. Esp8266 wi-fi module [27] is used for convenience and affordability compared to the SIM900,800 GPRS module [28]. SIM Card wi-fi router has been used in this module to provide a wi-fi access point to connect more than one device within a specific range, saving cost and working more efficiently. LED light represents the locker of a real vending machine that has been used to simulate our method to determine if the locker is open or not. Figure 15 shows the main components used in the prototype.

Prototype of Vending Machine
To simulate our hardware operation, we have developed a prototype vending machine with a metal body and used transparent plastic as a locker cover, as depicted in figure 16. A set of electronic cabinet lockers shown in figure 17(a) has been used. The front hook of the locker is attached to the transparent locker cover, and the remaining part of the locker is attached to the metal body of the prototype vending machine. The Electric Cabinet Lockers are plugged in RS485 Control Board as figure 17(b), which connects the lockers with the Arduino's power supply and controls the voltage supply to the lockers. As soon as customers purchase specific products using Digital Payment through Mobile App, the payment record has been saved, and the vending machine receives the request to dispense the ordered items. The status of specific lockers containing ordered products will be updated from "off" to "on" in the database, as shown in figure 18.

Figure 18. Status of Lockers in Vending Machine
Moreover, Status "on" means the voltage is supplying to the specific lockers and status "off" means otherwise.
To dispense products by unlocking specific lockers, the status is persisted "on" for a certain period of 60 seconds. During the period, the microcontroller reads the database continuously through API, finds the lockers with the status "on," and supplies the voltage to the As the electric locker can receive the voltage get opens when the supplied voltage is passed to the intended lockers, which contain the ordered items. When the power is turned off, the voltage supply is stopped, and the locker can be locked again.

RESULTS AND DISCUSSION
We used Arduino, and undoubtedly, Arduino is less expensive than Raspberry Pi. Nevertheless, the cost was, by all accounts, not the only motivation to pick Arduino. To keep the simplicity of vending machine design, we need a plug-and-play device that is available for service by turning ON and OFF switch any of the time. We also used ESP8266, a low-cost WI-FI microchip that made the design simple but adequate for production, ensuring high performance.
The mobile application we developed appropriately worked to select the products from the vending machine. The digital payment system (bKash) we integrated was one of the most challenging parts of this work. To make it fully functional, we went through the bKash API documentation and wrote the logic as per their payment system requirements on the backend. As a result, a new user needs to agree with bKash only for the first transaction and for the subsequent transactions onwards, they need to provide only a pin code which makes the payment process hassle-free, convenient and fast for the users. The digital payment system (bKash) API implementation worked for each transaction and stored the transaction data in the database storage. If there are any failed transactions, it does not affect the database storage. An alert message is displayed on the app to show that the transaction was not successful. After successful payment is made, the status of the LED is updated to turn on. The Vending Machine controller checks the database periodically and detects the status of the LED. As soon as it identifies the LED with status on, the LED turns on. In Figure 19, LED 2 and 4 is turned on after a successful transaction representing the locker 2 and 4 is opened.  Figure 19. LED Turned on After A Successful Transaction Therefore, it signifies the locker is on in the actual vending machine and ready to dispense it to the consumer. The LED status is updated to turn off within 2 to 3 seconds, indicating that the locker is closed.  Table 2 summarizes the performance test result of 150 consecutive API calls. Figure 20 represents the average response time of the API request calls. The average time to complete a whole purchasing process has been depicted in Table 1. The user gets the list of products of a particular vending machine. The average time takes 2100 milliseconds, mainly fetching from the database with a GET request. The user selects the products from the list and presses the payment button. After providing the user payment pin, it takes 6300 milliseconds to process the payment in the digital payment method system (bKash) and update the payment status on the database. As soon as the database updates with successful payment, the LED turns on within 2300 milliseconds on average, the locker opens, and the machine dispenses the product. The system needs additional 3800 milliseconds to turn the LED off, which overlaps with the time used by the consumer to collect the order from the vending machine. The result of the overall cycle is completed in 14500 milliseconds which can provide a good buying experience. In addition, in the prototype vending machine, we simulated the purchasing experience as shown in Figure 21. After a successful transaction with the bKash digital payment system using the mobile app, the specific lockers have been opened to dispense the products to the customer.

CONCLUSION
In this paper, a presentation of an innovative IoT platform has been aimed to be supported, covering a wide range of industries, devices and applications. We designed an intelligent application of vending machine for our country Bangladesh, which will be pretty efficient and helpful for many aspects. This paper's novel and cost-effective approach integrates mobile applications and payment gateway and securely purchases smartphones with digital payment methods. This IoT solution will provide a new experience to the customers' buying products at their convenience, is cost-effective, user-friendly, and easy to operate. Moreover, the same application incorporates a digital payment (bKash) method that makes a trouble-free experience, unlike the traditional approaches. Thus, this innovation can be extended significantly in various industries to take it to the next level of technological advancement in IoT sectors.