Home » Apps » Android App to remotely control a robot with the accelerometer via bluetooth

Login with your Social Account

Android App to remotely control a robot with the accelerometer via bluetooth


Discover how to control the movements of a robot with the accelerometer of your Android device using AppInventor2 and bluetooth.

Here, we describe how to develop an application with AppInventor2 to remotely control a mobile robot with the accelerometer via bluetooth connection.

In this entry, we firstly describe an application in AppInventor2, whose purpose is to detect a bluetooth device installed in a robotic and send a set of movement commands based on measurements obtained with the accelerometer of your mobile phone. Since AppInventor2 is used, these developments will only work on Android devices.

Create a new project in order to design the user interface. In this demo application will use a ListPicker to connect a bluetooth device (allows you to display the list of available bluetooth devices), a button to turn the accelerometer on and off, another button to disconnect the bluetooth and finally a button to close the application. The application requires in addition to a component of type bluetooth client that will manage communications with our robot.

The appearance of the user interface obtained, in our case, is the following:


You will find both the buttons and the ListPicker object in the user interface section. Rename the buttons to turn on the accelerometer, turn off the bluetooth and close the application to: activate_accelerometer, disconnect and close, respectively. The ListPicker component has been renamed to connect_bluetooth. For other components, we will use your name by default, i.e., BluetoothClient1 for bluetooth client (in the connectivity section), which will allow us to connect by bluetooth and AccelerometerSensor1 (in the section on sensors) accelerometer sensor.

In order to distribute the buttons, components such as TableArragement and HorizontalArragement (within the layout section), have been used. Although they are not necessary for the functioning of the App, will help us distribute properly each component across the App’s screen. We also have added a wallpaper for aesthetic purposes. It is worth noting that the neither bluetooth client nor the accelerometer sensor are visible in the interface, and therefore they appear just below the screen, as shown in the previous figure. When you are done with the interface, you need to program it. In order to do so,  access to the application code to by clicking on the tab/button “blocks”.

During initialization, the application sets enable properties of buttons to true or false as needed. The event for closing the application it is managed with the close button on the click event.


On the other hand, the disconnect button will also set enable properties of buttons to true or false, but in the opposite way. In order to connect to a bluetooth device, it is necessary to first list available devices and then specifically connect to the one selected. In order to do so, we first focus on the BeforeSelection event, which will create a list with all available bluetooth devices with their names and MAC addresses. In the AfterSelection event is where we do the bluetooth connection with the selected device and check is connection has been successfully stablished.


We have also created a set of 9 procedures to send a character through bluetooth, which will be received by our robot. In particular, we have defined the following procedures: front (“a”), back (“b”), left (“c”), right (“d”), front_right (“e”), back_right (“f”), front_left (“g”), back_left (“h”) and stop (“i”).


Thus, the AccelerometerSensor1 object includes an event which detects changes on the meassured acceleration. It provides values on 3D axis (X-Y-Z) from -9 to 9.


Upon X-Y measurements we have divided all possible cases into 9, considering 3 cases on each axis. If measurements are between -3 and 3 then it will be considered as zero, while if measurements are above 3 then it will be considered as positive and below -3 as negative. This renders all 9 cases as shown:


Here you will find the project file (.aia) and the .apk file to be installed on your Android device. Enjoy it!

Caterpillar robot

In this post you will find an example of a remotely controlled caterpillar robot with this App:

Design of a printable caterpillar robot


      Discover how to design all the parts of a printable caterpillar robot in 3D, assembling and electronics also provided. Relacionado

Posted in Grade, High School, Robots (other), Self-taught, Wheeled Robots | Comments Off on Design of a printable caterpillar robot


%d bloggers like this: