Interface and application programming


Assignments:

  • write an application that interfaces with an input &/or output device that you made, comparing as many tool options as possible

This week is meant to learn about interfacing and application development. As I said in networking week, I will be continuing networking part here. I am using wireless communication using bluetooth module, HC05. The plan is to write a mobile application for controlling LED. I haven't build any android apps yet. So I'm excited. I need to build another app for final project later. I am using MIT app inventor for app development. I am using my project board, which I had developed last week, for this assignment. Design files are available there.

The app should contain a button for connecting to HC05 bluetooth module first. If connecttion is successful app should notify that its currently connected to the device. Then there will be two buttons. One for switching the LED On and the other for switching LED off.

Here is an image of HC05 bluetooth module.

hc05 bluetooth module

App inventor is pretty easy to understand. Goto http://ai2.appinventor.mit.edu and login with gmail account. From project menu select new project. App inventor has two windows- Designer and Blocks. Designer window is used for developing user interface and Blocks window is used for developing the logic. Blocks window is similar to Scratch application where we can drag and drop logical blocks. In Designer window we can design buttons, colors, images etc. We can also add sensors, database etc.

  • I selected a listpicker for listing all bluetooth devices and two buttons switching LED on and off.

    app ui
  • Logics can be applied from block window for each of the element selected from designer window.

    app ui
  • I used the following logic code blocks.

    logic blocks logic blocks
  • Now we have to export the apk file. There are methods - either download into computer or read generated QR code for downloading app directly into mobile phone. I used QR code method.

    app export

Coding

I connected LED to pin PD5. I am writing code in arduino IDE. PD5 curresponds to 5 in arduino. Also Rx of the bluetooth module was connected to Tx of the board and Tx of the bluetooth was connected to the Rx of the board. Code is given below.

void setup() {
pinMode(5,OUTPUT); //PD5 equivalent to arduino 5
Serial.begin(9600);
}

void loop() {
char data;
if(Serial.available() > 0)      // Send data only when you receive data:
{
data = Serial.read();        //Read the incoming data & store into data
Serial.print(data);          //Print Value inside data in Serial monitor
Serial.print("\n");
if(data == '1')              // Checks whether value of data is equal to 1
digitalWrite(5, HIGH);   //If value is 1 then LED turns ON
else if(data == '0')         //  Checks whether value of data is equal to 0
digitalWrite(5, LOW);    //If value is 0 then LED turns OFF
}
}

Output

Downloads

App inventer project - Download

apk download - Download

Code - Download