Bluetooth Android Controlled MBED
Remote control MBED applications using Bluetooth as wireless protocol¶
There have been several blogs on how to communicate with MBED using a Bluetooth module (HC-05 ) module. I will try to bring all the information on one page from android application development to firmware on MBED. Hope this helps :)
Ingredients of the experiment¶
- 1. Bluetooth HC-05 ( pin description of the same can be referred to https://mbed.org/users/edodm85/notebook/HC-05-bluetooth/
- 2. Android Phone
- 3. Installation of Android development environment using MIT App inventor http://appinventor.mit.edu/explore/get-started.html
Connecting HC05 with MBED¶
| Pin- HC05 | Pin-MBED |
|---|---|
| 1-Tx | P10 - Rx |
| 2 - Rx | P9 - Tx |
| 12 - 3.3V | Vout - 3.3V |
| 13 - GND | GND |
| 31 - PIO8 | -- |
| 32 - PIO9 | - - |
| 34 - PIO11 | GND or 3.3V |
Hardware¶
Building Android App¶
Main Screen¶
There are 4 buttons which are by default assigned values as follows .
| Button | Assigned Value |
|---|---|
| Button#1 | 49 |
| Button#2 | 50 |
| Button#3 | 51 |
| Button#4 | 52 |
The assigned value is sent once and is seen in "send" box ! The values assigned to button#x can be modified by updating the text box at the bottom of the application .
Button Logic¶
Finally the button logic logic is same for all the four buttons , the data is read from the text box and sent over bluetooth , the data is entered in italic .csv format bold 11,22,33 or simply bold 11 for a single byte .
The text box is updated !! Followed , by the send operation , one byte of data (length byte) is read and indicates the total byte that will be sent by MBED . Once the length byte is received , the bluetooth module reads so many bytes of information.
| Length | Byte 1 | Byte 2 | Byte 3 | Byte 4 | ..... |
|---|---|---|---|---|---|
| n | 11 | 22 | 33 | 44 | ..n bytes |
Check out the video¶
Firmware for MBED¶
include the mbed library with this snippet
#include "mbed.h"
Serial pc(USBTX, USBRX);
Serial device(p9, p10);
DigitalOut led1(LED1); /*On board LED 1*/
DigitalOut led2(LED2); /*On board LED 2*/
DigitalOut led3(LED3); /*On board LED 3*/
DigitalOut led4(LED4); /*On board LED 4*/
unsigned char recivedchar;
void send_bytes(uint8_t len ,uint8_t data)
{
device.putc(len);
while(len>0) {
device.putc(data);
len--;
}
}
int main()
{
unsigned char rx;
device.baud(9600);
while(1) {
if(pc.readable()) {
rx = pc.getc();
device.putc(rx);
pc.printf("\n\nreceived : %x",rx);
pc_activity = !pc_activity;
}
if(device.readable()) {
rx =device.getc();
pc.printf("\n Received %x \nSending : %x",rx,rx);
switch (rx) {
case 49:
send_bytes(1,rx);
break;
case 50:
send_bytes(2,rx);
break;
case 51:
send_bytes(3,rx);
break;
case 52:
send_bytes(4,rx);
break;
}
}
}
}



