Android Application Design with MIT App Inventor for Bluetooth Based Mobile Robot Control

In this study, a Bluetooth-based Android application interface is developed to perform a manual and automatic control of a four-wheel-driven mobile robot designed for education, research, health, military, and many other fields. The proposed application with MIT App Inventor consists of three components: the main screen, the manual control screen, and the automatic control screen. The main screen is where the actions of the control preference selection such as manual control and automatic control and the Bluetooth connection between the mobile robot and Android phone occur. When the robot is operated manually for calibration or manual positioning purposes, the manual control screen is employed to adjust the desired robot movement and speed by hand. In the case of the need for automatic motion control, the desired robot position and speed data are inserted into the mobile robot processor through the automatic control screen. At the first stage of the work, the proposed Android application is developed with the design and block editors of the MIT App Inventor. The compiled application is then installed on the Android phone. Next, the communication between the Arduino microcontroller used for the robot control with the Bluetooth protocol and the Android application is established. The accuracy of the data dispatched to the Arduino is tested on the serial connection screen. It is validated that the data from the Android application is transferred to Arduino smoothly. At the end of this study, the manual and automatic controls of the proposed mobile robot are performed experimentally and success of the coordination between the Android application and the mobile robot are demonstrated.

leakage and live intrusion, and manually controlling the robot. [25]. Meteab et al. carried out the control of a robot vehicle containing Arduino microcontroller and bluetooth module with Android smartphone application [26]. Qadri et al. designed a robot with a 3D printer to measure carbon monoxide, temperature and humidity in mines where working conditions are dangerous and difficult. They developed an Android application for the control of this robot. The results of the measurements examined with a smart phone and they achieved 100% accuracy up to 10 m distance [27]. Papcun et al. communicated between mobile robot Khepera III and mobile device using bluetooth and Wi-Fi interface. They applied face recognition by sending the image taken from the camera on the robot to the mobile device [28]. Eren and Doğan realized the design and production of a high-performance and low-cost vacuum cleaner robot that can be controlled with a smartphone. In the software design of the robot, they designed an Android application for a bluetooth-based remote control. With the application, the operation of the vacuum and brush motor can be controlled while the robot moves [29]. Kırlı et al. who created the environment map with a mobile robot with six wheels and differential drive, made mobile robot operations and Android device developments using the robot operating system (ROS). While the camera image and the calculated map information taken from the mobile robot are transferred to the Android device, the data controlling the driving of the robot are transferred from the Android device to the robot [30]. Molnar et al. presented a study on the design and control of a mobile robot that maintains its balance by standing on two wheels. They made PID control using the ESP8266 microcontroller. By designing a mobile application with MIT App Inventor, they provided control over a mobile device and on a personal computer using the web interface [31]. Varga et al. have designed a mobile application for the Robot Soccer game that performs direction and motion control with an accelerometer by choosing between players 1 and 2 via bluetooth [32]. Fahmidur et al., with the Mobizen application, mirrored the screen of the Android phone to the computer and performed the robot control with bluetooth [33].
In this study, an Android application is developed to perform manual and automatic control of a 4-wheel drive mobile robot, whose design and prototype are realized. The interface and programming of the application are designed with the designer and block editor in MIT App Inventor. In studies related to this subject in the literature, mobile robots can only be controlled manually with the designed Android applications. This designed application offers both manual control and automatic control options. The application interface consists of three parts. The first part is the main screen seen when the application is opened, the second part is the manual control screen and the third part is the automatic control screen. On the main screen, it is possible to have a bluetooth connection between the robot and the smart phone/tablet, closing the application and send information for resetting the microcontroller card. It is also possible to pass to other screens. On the manual control screen, there are direction, speed adjustment, led and fan buttons to manually control the robot. On the automatic control screen, position reset and targeted axis and speed information are sent to the robot for automatic control of the robot. After the designed application was compiled, it was installed on the smart phone. Arduino Due microcontroller and HM-10 bluetooth module were used to test the accuracy of the information sent to the processor connected via bluetooth when the buttons in the application are pressed. By providing a bluetooth connection between the application loaded on the smartphone and the Arduino, the data sent from the application was observed on the Arduino Integrated Development Environment (IDE) serial screen and its accuracy was proven. In line with the data obtained, real-time manual control of the mobile robot with the Android application and automatic control in accordance with the references were carried out with the 1 3 program uploaded to the Arduino microcontroller, and the graphs of the robot control performances were given.

Mobile Robot
The mobile robot shown in Fig. 1 has a 4-wheel structure, each of which is connected to a 12 V DC motor, and moves with a differential driving system. Differential driving technique is a driving style based on having different speeds two of the four independent wheels on the common axis of the mobile robot. If the two wheels on the right and the two wheels on the left have different speeds, the vehicle turns to one side. If the wheel speeds have the same speed and direction, the vehicle go straight.
Robot power requirement is provided by the LiPo battery. A boost converter is used to stabilize the voltage value of the motors. The speed control of the motors is realized with two Sparkfun Monster Moto Shields as Pulse Width Modulation (PWM) controlled. These PWM values are sent by the Arduino Due microcontroller, where peripherals such as fan and headlights are also controlled. The data sent from the application installed on the smartphone is transferred to the Arduino with HM-10 BLE (Bluetooth Low Energy) bluetooth 4.0. According to these transferred values, motors, fans and headlights are controlled. The block diagram of the mobile robot is given in Fig. 2.
The connections between blocks in here is P: power, PD: PWM and direction E: encoder and C: Control.

Android Application Design
Since the mobile robot is desired to be controlled in two different ways, manual and automatic, the Android application interface is divided into three parts to both reduce complexity and provide visuality. These parts are Main screen, manual control screen and automatic control screen.

Main Screen
It is the screen that appears when the application is first run. On this screen, the bluetooth connection between the robot and the Android device is provided. In addition, there are selection buttons to pass to other parts, reset and application close button. Figure 3 shows the main screen interface and logic blocks.
The application communicates with the robot with the bluetooth protocol. Therefore, the one needs to know the device's bluetooth address and connection status. In Fig. 4, the bluetooth connection workflow diagram and the blocks that perform this flow are given.
First of all, to find the device to be connected, scanning is done, selection is made from the list and then the connect button is pressed. If the connection is completed successfully, the 'connect' text turns green and the 'connection established' text appears at the bottom. If it fails, a 'disconnected x' warning appears in the status section. After the connection is established, the manual control button can be pressed to transition to the manual control screen, and the automatic control button can be pressed to transition to the automatic control screen. If these buttons are pressed without establishing a connection, the transition is provided, but data cannot be sent. Figure 5 shows the flowchart and logic blocks of these buttons. If the microcontroller software is to be restarted, the reset button can be pressed, if the application is to be closed, the exit button can be pressed. Thanks to the information to be sent to the device with the reset button, the software or hardware reset can be performed. When the exit button is pressed, a warning message is displayed to the user. If the user selects the 'yes' option, the application will be closed, if the user selects the 'cancel'

Manual Control Screen
It is the screen where the manual control of the mobile robot is provided. On the manual control screen given in Fig. 7, there are direction buttons, speed adjustment buttons and   Figure 8 shows the flowchart and logic blocks of the direction buttons and the stop button. The speed of the robot is adjusted by changing the PWM value sent to the robot with the speed increase/decrease buttons. In the stage setting at the top of the screen, the increase/ decrease rate of the PWM can be changed. If no change is made to the stage value, the PWM value increases by 1 by 1. While the PWM value is displayed at the top of increase button, the approximate speed value calculated according to the motor speed and wheel diameter can be seen among these buttons. The work flow chart and logic blocks of the speed increase-decrease buttons are shown in Fig. 9. Since the PWM signal is used as 16 bits in the microcontroller, it varies between 0 and 65,500 values. However, in order to limit the motor voltage to a certain value, the PWM upper limit is chosen as 51,500 and where the no load rotation speed at a maximum of 88 rpm. The motor speed calculated based on the PWM values adjusted from the increase/decrease buttons was considered equal to the robot speed and was calculated according to Eq. 1. where V is the motor speed, r is the wheel radius of robot and pwm is the entered pulse width modulation value. In Fig. 10, flow charts and logic blocks of the return, fan and led buttons on the manual control screen are given. When the back button is pressed, the application returns to the main screen. There are four leds and one fan on the robot. While the LED button turns on and off the LEDs attached to the robot for lighting purposes, the fan button starts and stops the fan installed for cooling.
Since the leds and fan buttons work in the same way, they are shown together in the flow chart.

Automatic Control Screen
In the mobile robot processor, the speed and position of the robot can be controlled with algorithms such as PID, fuzzy, artificial neural networks, and soon. After the required algorithms are loaded into the robot processor, what needs to be done is to enter the target speed and position information for the robot. This process is performed on the automatic control screen of the Android application. As seen in Fig. 11 Fig. 9 a Flow chart and b logic blocks of speed increase-decrease buttons reset button, target position and speed entry, delete and confirm button and back button on this screen. While performing automatic control, it may be necessary to reset the previous position information in the place where the robot is located and start from the origin point. For this reason, before entering the targeted axis values, information is sent to the Arduino with the 'reset position' button to reset the robot's position. The x and y axes that the robot wants to go are entered in meters and the reference speed in m/s by the user. Then, when the OK button is pressed, these data are sent to the microcontroller and these values are processed as a reference. In case of entering the wrong value, the values can be re-entered by pressing the delete button. When the back button is pressed, it returns to the main screen. The flow chart and blocks of the automatic control screen are shown in Fig. 12.

Experimental Results
When the application design was completed, the compilation process was done and an.apk file of 5.5 MB was created. For the functional test of the application, the program with the workflow given in Fig. 13 was written on the Arduino Due microcontroller and a bluetooth connection was made between the smartphone and Arduino as in Fig. 14.
After realising a bluetooth connection between the smartphone and the Arduino microcontroller, the manual control screen in the application interface was switched and various buttons were pressed on this screen. When the buttons in the Android application are  on signal is sent, while the red ones indicate that the led/fan is sending the off signal. If the direction and speed buttons appear fainter than other buttons, it means that that button is pressed. As seen in Fig. 15, the value that should be sent via bluetooth and the value read   Figure 16 shows the speed values of each motor of the four wheel drive mobile robot in Fig. 1, which is moved in different directions in line with the information received from the application. In Arduino, all motors are programmed to go at equal speed while the robot is moving forward. As the robot moves in the right or left direction, the motor speeds are changing. 20,000 PWM values were sent to the robot from the application and the forward direction, right forward and left forward buttons were pressed respectively. While the motor moves forward in 0-4.5 s, it moves in the right forward direction in 6-10.5 s and in the left direction in 12.5-17 s. While switching between the buttons in the application, only the PWM value goes to the microcontroller. When there is no direction information in the program written in Arduino, the motors stop with their own inertia. Therefore, there was a In Fig. 17, the application screenshot of the movement in the 0-4.5 s interval is shown. The PWM value was determined to 20,000 and was sent to the microcontroller with forward button. The speed value calculated with this PWM value according to the formula in Eq. 1 is 0.37 m/sec. In Fig. 16, 34 rpm was measured for this time interval. When this value was converted to the unit of m/s with Eq. 2, it is seen that the robot speed in this range was 0.37 m/sec.
where Vrpm is the measured speed of motors and r is the wheel radius of robot. The PID control algorithm, whose block diagram is given in Fig. 18, is used to perform automatic speed and position control of the mobile robot. As seen in Fig. 19, these values were sent to the Arduino by entering the reference y-axis as 2 m, x-axis as 0 m and the speed as   Fig. 20 are examined, it is seen that the automatic movement is performed successfully.
In Eq. 3, x is the position, V is the speed and t is the time. In the robot automatic control diagram, Kp, Ki and Kd are proportional, integral and derivative PID coefficients, respectively and e is the error signal.
As can be seen in Fig. 20, the robot position increased linearly and the robot 2-m reference position reached in 9 s with an error of 0.09 s. After 0.02 m/s overshoot at the start of the move, the robot was reached the steady state in 0.26 s and converge to the reference value.

Conclusion
In this study, an Android application was developed with MIT App Inventor for bluetoothbased control of a 4-wheel-drive mobile robot. While the application interface was created in the MIT App Inventor designer, it was made with the drag and drop method in the block editor. When the application installed on the phone is run, the bluetooth connection is provided on the main screen that opens and the transition to other screens can be selected. Arduino Due microcontroller was used to test that the values to be sent from the application are sent correctly when the buttons are pressed. A connection was established between the HM-10 Bluetooth module attached to the Arduino and the smartphone. In the program written to receive data in Arduino, the values sent with the application were transferred to the serial screen of the Arduino IDE program and examined and it was shown that the values were transferred as planned.
In line with the information sent to the Arduino, manual and automatic control of the four-wheeled mobile robot was carried out. the automatic speed and position control of the mobile robot was controlled with PID in line with the reference values sent from the application to the robot microcontroller. In the given graphics, it is presented that the mobile robot is controlled effectively manually and successfully captures the reference values with automatic control. The designed application can be installed on different Androidbased phones or tablets, it can connect with any processor used in bluetooth protocol and can be used on different robots according to the program that the user will write on the microcontroller.