Creating an App to Control a Robot with Sequential Commands

Creating an App to Control a Robot with Sequential Commands  


Today, we will see how to use Sequential Commands to control a robot with an app.

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 an app using the MIT App Inventor to control it. 

What you'll need:
  • A Mobile Phone
  • A Laptop
Step 1: Designing the layout of our app

Firstly, open the MIT App Inventor and then click on 'New Project' and rename the project to 'Robot_Sequential_commands'. 

After that, change the background colour of the screen to black and then add a Text Box to the screen. Change its font size to 18, its height to 50 pixels and its width to fill parent. Add text in that box -"Choose a duration for go ahead and stop''.
After that, add a Horizontal  Arrangement below the Text Box and change its height to 50 pixels and its width to Fill Parent. In that Horizontal Arrangement, add a slider and change its ColourLeft to blue or any colour that you like and then change its width to 200 pixels, its MinValue to 100 and its MaxValue to 10000. Rename the slider to Go_Ahead_Slider. This Slider will determine the time for which the robot will move ahead and stop. Then, add a Text Box beside it and change its Background Colour to white. But don't add any text to it. 

Then, add another Text Box below the Horizontal Arrangement and change its text size to 18, its height to 50 pixels and its width to Fill Parent. Add text to it- "Choose duration for turning". 
After that, add another Horizontal Arrangement below the Text Box. Do the same with the previous Horizontal Arrangement. Add a Slider and do the same with the above slider. Then, add a Text Box beside it and then do the same with it. Rename the Slider to Turn_Duration_Slider. This Slider will help us determine the duration the robot will turn.

Then, add another Text Box below the Horizontal Arrangement and then select its font size to 16, change its height to 60 pixels and its width to Fill Parent. Add text to it- ''Choose any amount of moves, then start sequence''. 
Below the Text Box, add a Horizontal Arrangement and add 1 Spinner to the Horizontal Arrangement. This Spinner will help us select the moves or the sequence of the moves we want by showing a dropdown and the list of moves you can do. Change the width of the Horizontal Arrangement to Fill Parent and its height to 70 pixels, and after that, type the list of moves we want in the spinner in the ElementsFromString option, like stop, right, left, forward. Then, add a button next to the spinner. Change its width to Fill Parent and its background colour to grey. Add text to the button- Start Sequence. This button will make the sequence start. 

Next, add a Horizontal Arrangement below it and change its width to Fill Parent. Add 2 Text Boxes next to each other in the Horizontal Arrangement. Change the first one's width to 100  pixels and change the other one's width to Fill Parent. Then, add text to the first one- Moves: and don't add any text to the second one. We'll get to see the list of moves in the second text box. 

Then, add one last Horizontal Arrangement below and change its width and height to Fill Parent. Then, add 2 buttons to the Horizontal Arrangement such that they're next to each other, their heights are set to Fill Parent and their widths to 200 pixels. Then, remove the text from both of them and change their shape to a rectangle. Change their background colour to black and then add one last component. Add a clock to the layout, and then set its time interval to 1000. Then our design layout is ready!

Now we'll write the code.

Step 2: Writing the code

I've provided the step-by-step code below. Follow those steps to upload the code. 





























































































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!

Comments

Popular posts from this blog

Creating a Home Automation Project Using Xiao board and Wi-Fi

Making a Neon LED Sign Board

Creating a Home Automation Project Using MIT App Inventor