MIT App Inventor for Arduino

Building an Android application is one option to control your robot project or anything that comes to your mind. And with the use of the MIT App Inventor 2, you can easily create an Android application.

In this tutorial, we will learn to create a simple Android application which can control the state of the LED connected to Arduino Uno board. Bluetooth communication protocol will be use via HC-06 bluetooth module.

In the Arduino Uno, we will create a circuit according to the following diagram:

 1
 2#include "SoftwareSerial.h"
 3
 4#define LED_PIN 13
 5#define HC06_RX 2
 6#define HC06_TX 3
 7
 8SoftwareSerial HC06(HC06_RX,HC06_TX);
 9
10bool LED_STATE = false;
11String cmd = "";
12
13void setup() {
14  // put your setup code here, to run once:
15  HC06.begin(9600);
16  pinMode(LED_PIN, OUTPUT);
17  digitalWrite(LED_PIN, LED_STATE);
18}
19
20void loop() {
21  // put your main code here, to run repeatedly:
22  while(HC06.available()>0){
23   cmd+=(char)HC06.read();
24  }
25
26  if(cmd!=""){
27    cmd.trim();  // Remove added LF in transmit
28    // We expect Command from bluetooth
29    if (cmd.equals("1")) {
30      LED_STATE = true;
31    } else if (cmd.equals("0")) {
32      LED_STATE = false;
33    }
34
35    cmd=""; //reset cmd
36  }
37
38  digitalWrite(LED_PIN, LED_STATE);
39}
...
cpp

MIT App Inventor

Follow the following sketch for the MIT App Inventor.

You may download the Android application here: DOWNLOAD THE ANDROID APP

Part 1:

Part 2:

I hope I am able to impart a little information to you, but if you have any question, please do not hesitate to leave your question in the comment box. Thank you and have a good day. Happy tinkering.



Posts in this series



GitHub-flavored Markdown & a sane subset of HTML is supported.