Menu Close

Sending and Receiving Data with HC-05 – MIT App Inventor

This tutorial of Robo India explains how to Control LED with bluetooth module HC-05 using MIT App Inventor.

1. Introduction:

Go to the link ai2.appinventor.mit.edu. Sign In with your existing gmail account. To start making your application, click on the Projects menu on the top left of the screen and select the “Start new project” and then give the name of your project.

2. Designer Panel:

Select the ListPicker component from user interface. ListPicker is the button, which displays the list of available bluetooth devices and handle the selection. You can change the text display on the listpicker to properties panel. You can also change the height, width, color using the same panel.

ScanButton_HC05

After this, click and hold on the word “Button” in the palette, drag your mouse over to the Viewer and drop the button over the horizontal view , and give name disconnect.

disconnect_hc05

Add a label text (optional), as a status about bluetooth connection.

Add two buttons, to make LED on and off. Also add bluetooth client component to establish bluetooth connection.

Add a text box to receive data from connected device. The reception of data is implemented using a timer. Per second, the client checks to see if the data is available. If it is than it reads and display the data. So, for this add Clock sensor component which is also a hidden component.

3. Block Editor:

The Blocks Editor is where you program the behavior of your app. There are Built-in blocks that handle things like math, logic, and text with each components you have added.

Click on the list picker and select ListPicker Before Picking and set the elements of list as available bluetooth devices.

Again click on list picker and select ListPicker After Picking to established connection between selected device and application. And by clicking on the disconnect button, add following blocks to disconnect connection.

Now, add blocks for led on and led off buttons. Here, we are sending 1 to turn on led and 0 to turn off led according to code. You can change these.

You can apply condition that, function will occur only when the bluetooth is connected and to make led on and off using single button.

Add code to receive data from connected device.

You may download the source code of this App from here.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply