This tutorial explains the steps involved in building a Mobile App-based Device Control Block to control the operation of a Buzzer Block in the Temperature & Fire Monitoring & Alerting Tinker Block Application. You will specifically learn how to remotely control an actuator device from a mobile app screen.
Before building Mobile-based Device Control Block, please make sure to build:
Buzzer Block, Processor Block and Power Block
IoT-based Server Block
IoT-based Device Control Block
Device Integration Block
Go to MIT App Inventor and click to "Create Apps". Sign-in with your Google Account.
Once you sign-in, click on "New project" to create one and give it a name such as "Buzzer Control App".
Once the new project is created, drag and drop a "Label" user interface element into the blank mobile screen. Re-name the label as "BuzzerControlLabel". Change the label's Text property to "Buzzer Control: ".
Next, drag and drop a "List Picker" user interface element into the screen. Re-name the text-box as "BuzzerCommandsList" and change it's Text property to "Select a command from the list...". Add "TURN_ON, TURN_OFF" in the ElementsFromString property. In addition, increase the Width property of the List Picker to "Parent".
Next, drag and drop a "Label" user interface element into the screen. Re-name the label as "BuzzerCommandSelected".
Next, drag and drop a "Button" user interface element into the mobile screen. Re-name the button as "BuzzerControlBotton". Change the Text property of the button to "Send Command".
Next, drag and drop a "Label" user interface element into the mobile screen. Re-name the label as "CommandStatus". Change the Text property of the label to "Status" and increase the Width property to "Parent".
Finally, drag and drop "Connectivity->Web" component into the mobile screen and re-name it as "CommandWeb".
This completes the design of the mobile app screen. The same will be displayed as shown below:
10. Next, let's add a few blocks of code. Click on "Blocks" button option in the top-right corner of the window.
11. Add the following code blocks to read the selected command from the ListPicker and assign the same to the global variable "selectedCommand".
12. Next, add the following code blocks to send the selected command to ThingSpeak IoT Platform.
In the URL field of the code block, key-in the following:
https://api.thingspeak.com/talkbacks/99999/commands.json?api_key=XXXXXXXXXXXXXXXX
Where 99999 is the Talkback ID and XXXXXXXXXXXXXXXX is the Talkback API key which you created in ThingSpeak earlier.
13. Next, add the following code blocks to check whether the command was sent successfully to ThingSpeak or not:
14. The Mobile app is now complete and is ready for testing. Create an Android "apk" file by clicking the "Build" --> "Android APK (.apk)" menu option.
15. Once the build is complete, you will see a QR code displayed on the screen. Scan this QR code with an Android phone.
16. The Android phone downloads the App to your smartphone. If necessary, change the settings on your Smartphone to allow downloading an App from an unknown source.
17. Once the app downloads to your Smartphone, install the same and open the app.
18. When the App opens, select the "TURN_ON" command from the list and click the button. You will then notice the buzzer starts buzzing.
19. Select the "TURN_OFF" command from the list and click the button in the App. You will then notice the buzzer stops buzzing.
You can download the Project file for the above Mobile App by clicking this button: