Safety Features and Inventory Management for Vending Machine Using IoT

Article History: Received: 10 November 2020; Revised: 12 January 2021; Accepted: 27 January 2021; Published online: 05 April 2021 Abstract: Security features and inventory management for vending machines using IoT is a project which focus mainly on IoT implementation. Although IoT is no stranger to vending machine, the project takes different approach of IoT. It is not just about the inventory management, but also the security features. Since IoT requires internet connection and cloud storage, it requires a microcontroller that supports wireless connection. Therefore, all the operations including controlling the vending machine will be done using ESP32 microcontroller. Anything that are recorded from the vending machine such as the number of product left, the amount of money and the condition of it will be uploaded to the cloud storage, Blynk. Blynk app and cloud storage are easy to use without need of professional knowledge. The inventory management is done by monitoring the amount of the money and items. The safety features will be done using accelerometer and gyroscope, which will be detecting force on the body.


Introduction
Vending machine is an automated machine that sells goods such as foods, drinks, and cigarettes. Its principles are very simple, the customer makes the payment to the machine, then the good is retrieved either by released by the machine or need to be released by customer himself. Since these machines operate automatically without human monitoring, meaning they are vulnerable against various of crimes such as theft and vandalism. Both usually comes in physical form. The owners who placed their machines where the security level is low to none suffer thousands of ringgits of losing their machines and items. Most security features from vending machines are just structural features that absorbs the physical abuse from vandalism and just delaying the theft from being completed. Conventional method such as using CCTV does not protect the vending machine physically and need constant human monitoring. For security purpose, an embedded system needs to be created that integrates all sensors such as accelerometer, gyroscope, and GPS as security IoT system that protects vending machine from theft and vandalism. The system will be used as the real-time notification to alert the owner if such attempts is happening. An inventory management system (Patent No. 5207784, 1993), (Patent No. 6181981, 1996), (Patent No. 5706976, 1998) must be created that manage the inventory of the vending machine with IoT to solve such issue(S.V. . The system also will be used for notification on realtime situation to help the owner aware and manage the inventory. Vending machine also is being neglected in having proper inventory management. Most vending machines in Malaysia are traditional vending machine that are incapable for real time inventory monitoring. Vending machine owners waste more time and resources maintaining their machine inventory without foreseen it in real time (Ben Black, 2018). Vending machine items usually refilled based on schedule, without knowing the amount of money left, what type and number of items need to be refilled and without. The remainder of this paper is organized into four sections: 1) literature review, 2) materials and methods, 3) results and discussion, and 4) conclusion.

Literature Review
Three areas have been reviewed for this paper, which are security, inventory management, and data analyzation.

Security
Theft is the biggest concern for any vending machine given it is an automated that often left to operate itself. In 2019, Royal Malaysia Police successfully captured "Gedegang Gang" (Fuad, 2019), which consists of four men age from 23 to 29. The group is responsible for ten robberies in Klang Valley. The police seized a car, a drilling machine and six vending machines from them. Two of them were vending machine operators. The group is suspecting stealing the machines using the drill machine and removing them using lorry. From the observation, the machine received a very huge physical force to remove them using power tools. Therefore, detection of those forces can help prevent theft on vending machine.The propose of accelerometer and gyroscope sensor can help to detect the event, hence the owner can act based on the real-time status sent by the machine.
Vandalism is another common crime happens on vending machine. Alpine School District in Orem, Utah in 2019 reported to Orem police that the vending machine from Timpanogos High School was vandalized (Thomas, 2019), and the money was stolen. According to the CCTV, the man use crowbar to conduct his crime by prying open the vending machine. He is suspected to be responsible for six similar cases in Alpine School District alone. Police estimated about $8,000 were stolen and the damage worth about $20,000. Act of vandalism on vending machine will result a huge force exerted on them, resulting the machines to be damaged. Therefore, CCTV itself is not sufficient to help monitoring the vending machine.

Inventory Management
One of the most available way of implementing IoT using smartphone is using Blynk platform. An example is a work done byAlharbi in 2019. Fahd Alharbi from King Abdulaziz University, Kingdom of Saudi Arabia develop a liquid level monitoring and control system by implementing IoT. The system scope is developing an IoT system to monitor and control liquid from a distributed tank system. His prototype uses ultrasonic sensor to monitor the liquid level water pump to control it, Arduino board as the controller, and ESP8266 as wireless Wi-Fi module. The system is monitored and controlled over the internet via the Blynk platform. Since the platform has shown a very promising result, the same method will be implemented for this project.

Data Analyzation using Thingspeak
ThingSpeak is IoT platform developed by MathWorks, the developer of MATLAB. It allows the user to store and collect any data into their cloud and server. Kumar, Jilani, Hussain, & Raju.K, (2015) developed a project by collecting data from MPU6050 and upload it to ThingSpeak. This project used Raspberry Pi 3B+ to transmit a data and used Python for the processing. The project's aim is to send the readings of 3 axes accelerometer and 3 axes gyroscope by various hand gestures to ThingSpeak. Considering the efficiency of the software, the same method will be applied.

Materials and Methods
There are two section that need to be designed before the actual implementation can be made, which are the software and the hardware.
Based on Figure 1, LED, buzzer, LCD monitor, servo motor, ESP32, MPU6050 and push button, are group together as they are the main components used to build the vending machine. All components will be controlled by ESP32 microcontroller. The ESP32 then will send the data to Blynk. From Blynk, the data will be sent to ThingSpeak for data analysis.   A solution needs to be designed for security features and inventory management, since the project focused on these two features.Based on Figure 2, the security feature starts by turning on the MPU6050. The MPU6050 accelerometer then will read the linear acceleration. If the acceleration is more than parameter set, it will sound the alarm and send the data to ESP32, ESP32 will send notification to Blynk and the data will be sent to ThingSpeak.Whenemergency button from Blynk interface is pressed, the vending machine operation will stop and not in operational. Once it is released by the owner by pressing the button from Blynk interface, the machine will operate just as usual.On the other hand, based on Figure 3, once the vending machine is turned on, it will wait for coin to be inserted, once the coins reached total RM1.00 or more, the products can be selected. After a product is selected, it will be dispensed and the inventory such as amount of money and items will be updated to Blynk and the data will be sent to ThingSpeak. If the inventory is updated from the Blynk, the amount of inventory will be updated in the vending machine.
The selection of hardware that will be used for this project is based on the literature review, the availability, and the success rate that they can give. The MG996R servo motor with a maximum stall torque of 11 kg/cm will be used since the library is compatible with the ESP32 microcontroller. Apart from that, the MPU6050 sensors module, or the Micro Electro-Mechanical Systems (MEMS), which consists of a 3-axis Accelerometer and 3axis Gyroscope will also be implemented in this project to detect the force done on the vending machine. For the microcontroller board, the Espressif ESP32 DevKitC by Espressif which supports Wi-Fi and Bluetooth connection and has higher memory, storage and clock speed compared to Arduino Uno and NodeMCU ESP8266 is selected for the project design and implementation. Other than that, buzzer, LED, push buttons and LCD screen are also going to be used to mimic the alarm siren and light, to drive away the criminal from continuing stealing or vandalizing the vending machine, to imitate coin dispenser of vending machine, and to display commands of coin dispenser. The Push buttons in this project will be divided into 3 groups; to insert the amount of money, to select the product, and to reset the values of vending machine inventory. The LCD screen will emulate the function of display monitor of a real vending machine as visual interface between the machine and the customer.
Mostly, the software is based on the selection of the hardware used. The primary focus is to ensure the workability of the hardware, the integration, and the result that it can produce. The main software that is going to be used is Arduino IDE. It is used to program the ESP32 because of its compatibility with all the hardware used in this project. Most of programming for the hardware can be downloaded from Arduino libraries and plenty of tutorials are available. Next, Blynk is the most popular IoT platform designed to connect devices to the cloud, design mobile and web apps to control them, and manage thousands of deployed products. To use Blynk in this project, Blynk library specifically BlynkSimpleEsp32 is used. Blynk app also need to be installed to a smartphone to make an UI for the owner and the project. The design of vending machine for this project will be made in SolidWorks. SolidWorks is Computer Aided Development (CAD) software that can create 2D and 3D models. It is very easy to use and regarded to be more user-friendly than other CAD software. The dimensions of the project and the components' positions are also determined in SolidWorks. For the circuit design and simulator, EasyEDA software will be used. It is a web based electronic design automation software. Unlike Proteus, it needs an account and connected online to store any project made. EasyEDA is used instead of Proteus because it has more component libraries. Finally, the open-source IoT platform known as ThingSpeak is used to receive the data from Blynk, which is transmitted from ESP32. Data will be collected is the number of alarms, the amount of money paid, amount of money stored, amount of item 1 and amount of item 2.

Security features
MPU6050 required 5V power source to operate. This sensor only can be used using I2C communication. Buzzer and LED was set up as usual as using Arduino Uno. If any of the acceleration X, Y and Z from MPU6050 exceeds 0.2, buzzer and LED will be turned on. Figure 4 shows the LED and the buzzer turned on after the acceleration reached 0.2.
Using MPU6050_tockn (Takuto Sato, 2019), the acceleration of X, Y and Z axes can quickly be obtained, then it can be uploaded to Blynk. The ESP32 was programmed to send alarm notification to Blynk once the readings reached certain parameters, the parameters set for Acceleration X, Acceleration Y and Acceleration Z were 0.2 m/s. When the readings reached their parameters, the owner will automatically be notified by Blynk app using Notify function. Figure 5 shows Blynk app GUI for security feature and Figure 6 shows the Notify function displayed "VENDING MACHINE COMPROMISED" text.After being notified, the Emergency Button can be pressed by the owner to freeze the vending machine function and turn off the LCD screen. The purpose of freezing the machine function and turn off the LCD was to deceive the criminals that the machine was not operational.

Inventory management
There were five push buttons, divided into three groups. Group A; yellow and green push buttons for coin numbers, Group B; blue and white push buttons for item picking and Group C; red push button for resetting amount of money and items. Figure 7 shows the push buttons for vending machine.The LCD at first will display "Insert money" and "Amount of money:"texts. The "Amount of money:" text shows the amount of money inserted by the customer. Once the amount of money reaches RM1.00, the LCD will display "Pick an item". If the blue button is pressed, LCD will display "Item 1 picked" and if the white buttonis pressed, "Item 2 picked" will be displayed. After 2 seconds, the screen will restart back to the beginning. Figure 8 shows LCD monitor after selecting an item.There were two servo motors for each Item 1 and Item 2. The motors were attached to a large spring and items will be put between the helices. When blue button is pressed, motor 1 will be rotated and when white button is pressed, motor 2 will be rotated.
The amount of money and items stored in the vending machine can be monitored by the owner through the data received from ESP32. The data such as the amount of money being paid, the amount of money stored, the number of item 1 and 2 can be displayed using many value displays. Figure 9 shows the Blynk UI for inventory management. If the amount of money stored reaches RM10.00 and either amount of item 1 or 2 reaches 1, Blynk will notify the owner as reminder for refilling. Figure 10 shows the notification function. The owner can stop the machine from being used by customer for maintenance purpose. The LACK can be pressed to stop the machine from operating and the LCD monitor will display "Under maintenance", as shown in Figure 11.

Data analysis
The readings from ESP32 can be displayed in Blynk app using SuperChart function. TwoSuperChartwere made, first was for the number of alarms triggered and second was for the inventory management. Figure 12 shows the SuperChartfor inventory management. Blynk must use Webhook function and send it to ThingSpeak using API key provided by ThingSpeak for uploading the data. In this project, there were fiveThingSpeak fields for five readings; Field 1 was for the number of alarm triggered, Field 2 was the amount of money being paid, Field 3 was the amount of money stored, Field 4 was for the amount of item 1 left and Field 5 was for the amount of item 2 left. Figure 13 shows ThingSpeak Field for 3 graphs.  ThingSpeak has a feature to export the data in form of CSV file. The data was sort in time set by the user. Since there were five channels used in this project, there will be five columns in the CSV that can be analysed. Below tables were made by calculating the data from the CSV file. Table 1 shows the sum of each field. Based on Table 1, the vending machine makes the most revenue in March by RM8402.70 profit and item 1 was more popular than item 2 with item 1 sold for 8509 units than item 2 with 5857 units. Table 2 shows the number of alarms based on time in each month. Based on Table 2, the machine experience highest amount of alarm triggered between 8p.m. to 12a.m., which means in those time the machine was in the most vulnerable time and the operator must be on the highest caution to receive the alarm from that time. Table 3 shows the sum of money being paid sorted into 6-time frames. The higher amount of money paid means the higher usage of the vending machine by the user. Based on Table 3, the machine was least used during 4p.m. to 8p.m., 12a.m. to 4a.m. and 4a.m. to 8a.m., this shows those time were the moment the machine was least busy and suitable for refilling. While the machine experience highest usage between 8p.m. to 12a.m., which was not a suitable time for refiling.

Conclusion
It is concluded that this project achievedall its objectives. The security features and inventory management features were completed. The testing shows by detecting the amount of force exerted on the vending machine, the machine can be protected from theft and vandalism. The best speed of accelerometer that resembles human aggression is 0.2, by setting the MPU6050 to detect the force, the machine can now avoid from being harmed. Using Blynk app together with a microcontroller that supports Wi-Fi connection, the vending machine inventory can be managed using IoT (Hussain et al. 2020). Each function in vending machine such as inserting money and dispensing items were programmed to give their input into the app, and they are also can be controlled from the app. The ESP32 and Blynk was able to upload the data to ThingSpeak for both security feature and inventory management from the vending machine. The process is done via Blynk app. Each data was able to be displayed in ThingSpeak and can be downloaded in CSV form. This way data can be analysed for further study related to vending machine such as the sales of the items, the security of the vending machine location and the least busy time of the vending machine operation.
There are a lot of improvements can be done to this project. The sensor used for force detection needs to be more responsive but maintaining more accurate reading. The sensor needs to be able to detect such abnormal force but not too sensitive that it alerts the alarm in inappropriate condition. For inventory management, more functions need to be put to the vending machine so it can resemble a real vending machine better. This way the inventory management can be proved to be working in real life. The data uploaded to ThingSpeak needs to be more accurate for better data analysis. This can be done by refining the program or by uploading it to a local server.