2016/09/18

App Inventor 2 + Arduino - Controlling Arduino via Bluetooth using an Android Phone

This is a simple example on how to control the on/off of the LED attached to pin 13 of an Arduino Uno board using an Android App. developed using MIT App Inventor 2.

Schematic

- HC-06 RXD -> Arduino Uno Pin 3
- HC-06 TXD -> Arduino Uno Pin 2
- HC-06 GND -> Arduino Uno GND
- HC-06 VCC -> Arduino Uno 5V


Arduino Code

Note, using SoftwareSerial.h will invalid abs() - see http://forum.arduino.cc/index.php?topic=114532.0

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

char incomingByte = 'L';      // For incoming serial data

void setup() {
  mySerial.begin(9600);       // Initialize Software Serial
  
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

void loop() {
  if (mySerial.available() > 0) {
     incomingByte = mySerial.read();
     if (incomingByte == 'H') digitalWrite(13, HIGH);
     if (incomingByte == 'L') digitalWrite(13, LOW);
  }
}

App Inventor 2 - Designer


App Inventor 2 - Blocks


References:

App Inventor 2 Tutorial-Arduino Bluetooth Control
https://www.youtube.com/watch?v=pR2rTRDZ_-Y

Android MIT App Inventor – Auto Connect To Bluetooth
http://www.martyncurrey.com/android-mit-app-inventor-auto-connect-to-bluetooth/

Part 1: Basic Bluetooth communications using App Inventor
http://appinventor.pevest.com/?p=520

Using ListPicker for displaying and selecting from on screen lists
http://appinventor.pevest.com/?p=107

Bluetooth car with App Inventor 2.
https://www.youtube.com/watch?v=z0UQAyDZeBo

Простая Bluetooth машинка на Arduino
https://geektimes.ru/post/255442/

No comments:

Post a Comment