Creating Two Apps to Control a Robot via Two-way Phone Bluetooths

 Creating Two Apps to Control a Robot via Two-way Phone Bluetooth


Today, we will see how to use two smartphones' bluetooths to control a robot with two apps.

So, the robot works with the help of an LDR and a transistor. The robot consists of two wheels controlled by an LDR and a Transistor. The robot will have a mobile stand on top of it where the phone will be placed. The phone would've a screen where two black coloured blocks turn white according to our command, and due to its whitening, the LDR detects light, and with the help of the Transistor, the wheel would start rotating, making the robot go forward, turn right and left and stop. 

We won't learn how to make the robot, but we'll learn to create two apps that control it using the MIT App Inventor. 

What you'll need:
  • A Mobile Phone
  • A Laptop
This time, we'll be creating two apps to control the robot. Because we'll have an app that will send messages to the other via Bluetooth on both phones.

We'll first create the app that will receive messages. This app will be named ''Bluetooth_Server".

Creating the first app

Step 1: Designing the layout of the app

First, open the MIT App Inventor, click on 'New Project,' and rename the project Bluetooth_Server. Then, after opening the project, add a VerticalArrangement and set its height to 16 per cent and its width to Fill Parent. In this space, add 2 HorizontalArrangements. Change their heights to 8 per cent and widths to Fill Parent. Add a button, a label, and a text box to each of the horizontal arrangements. Such that the order of their arrangement should be button-label-text box. Change each of their heights and widths to Fill Parent. Add text to the button above as ''Accept'', the text of the label as ''Link Status''. Then, add the text to the button below as ''Disconnect'' and the text of the label below as ''Sender Mess''. 

After this, add a Canvas below the Vertical Arrangement. Then change its height and width to Fill Parent, and then add the Smiling Robot Face image to the canvas. 

Then, add another HorizontalArrangement below the canvas and change its height to 25 per cent and the width to Fill Parent. And in that HorizontalArrangement, add two text boxes side-to-side and change their heights and widths to Fill Parent. These are our physical components. 

For our non-visible components, add a notifier tool, a clock tool, a Bluetooth connector tool and a text-to-speech tool. 

The design of our app has been finished. Now we've to add the code.        

Step 2: Adding the code.

I've provided the code via step-by-step images. Follow them accordingly to add the code properly.


































Here, the name ''acce'' is the name of the Accept button at the top and the name ''disco'' is the name of the Disconnect button below the Accept button.





























































After that, click on 'Build' and then click on 'Android App(.apk)' and then you'll be able to download your app. After downloading it, you can scan the QR code to download the app on your mobile phone, too. 
And lastly, go to 'Projects' and then click on 'Export selected project (.aia) to my computer. This will help in opening your project whenever you want it on any computer temporarily.

The App Is Ready!

Now, the first app is done, we just have to make the last one. This app will send messages to the other app that we've just created. 

Step 1: Designing the layout of the app

So, the first step to designing our app would be to open the MIT App Inventor and click on New Project and rename it as ''Bluetooth_Client''. Then, add a HorizontalArrangement on the screen and rename it as Connection. Change its height to 15 per cent and its width to Fill Parent. After that, add a VerticalArrangement in the HorizontalArrangement and change its width to Fill Parent. Then, add a Text Box in the VerticalArrangement and rename it as Blue. Change its width to Fill Parent and its height to 58 pixels. Then, add another HorizontalArrangement to the first HorizontalArrangement and change its width to Fill Parent. After that, add a ListPicker and a button and rename them as Conn and Disconn, respectively and change both the height and width of those two to Fill Parent. 

Below the first HorizontalArrangement, add a HorizontalArrangement and change its height and width to Fill Parent and rename it as Sending. Add a VerticalArrangement in it and change its width to Fill Parent. Then, add a Text Box and a Button vertically and change their heights and widths to Fill Parent and rename them as TextInput and Sendu, respectively. 

Below that, add a VerticalArrangement and rename it as Buttons. In this, we're going to add all of the buttons. Then, change its height and width to Fill Parent. Then, add a button at the top and rename it as Forward and change its colour to green. This will be our Forward button. Then, add a HorizontalArrangement so that we can add two Left and Right buttons next to each other. Change its height and width to Fill Parent. Then add two buttons- Left and Right, next to each other in the HorizontalArrangement. Change their heights and widths to Fill Parent and their colours to Yellow. Then, rename them as lefty and righty. Then, add the last button, the Stop button, at the bottom and change its height and width to Fill Parent and its colour to Red. These are our Visible Components.

Now we have to add our Non-visible Components. Add a Notifier and a Bluetooth Component. 

The App Design is now READY. Now, we have to upload the code. 

Step 2: Add the Code

I've provided step-by-step images of the code. Add the code according to the images. 










After that, click on 'Build' and then click on 'Android App(.apk)' and then you'll be able to download your app. After downloading it, you can scan the QR code to download the app on your mobile phone, too. 
And lastly, go to 'Projects' and then click on 'Export selected project (.aia) to my computer. This will help in opening your project whenever you want it on any computer temporarily.

The App Is Ready!

In the next Blog Post, we'll see how to make the robot and how to use the apps that we've previously made.

Thank you!

Comments