Introduction: Bluetooth Bridge Between Android and Arduino - Btspp2file

btspp2file is simple, but very powerful utility for your Android and Arduino projects.

Source codes are available as open source on https://github.com/bcsedlon/btspp2file

Apk file is available on https://github.com/bcsedlon/btspp2file/blob/master/app-debug.apk
(you need to allow install unknown sources in security setting).

It is way how to communicate between smartphone with amazing compute power, sensors, internet connectivity, touch display and so on on one side and microchips (Arduino) with inputs outputs pins on second side.

World is full of used Android phones and tablets for (nearly) zero price. In Android device you get powerful computer with GSM, Wi-Fi, UPS (battery), touch screen, speaker, many sensors and nice case as hardware and linux based operating system with amazing universe of software on one side.

On second side are microchips like Arduino with many input output pins, UARTs, I2C and SPI buses which you need for control motors or servos and read out buttons and sensors.

Only problem is how connect these devices together and take out the best of each of them. In additional for low cost and low effort with focus to your idea and high added value instead of wasting time of repeating troubles with discrete modules.

It gives you possibility use amazing linux emulator https://termux.com/ for your sophisticated software tasks and control wired word on Arduino pins.

Other possibility is use Android automate tools like https://llamalab.com/automate/ or https://tasker.joaoapps.com/ which doesn't support Bluetooth data transfer and simply write and read files.

There are many tutorials how to use Arduino and HC-05 for example http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-in-slave-mode/

Step 1: How Btspp2file Works

btspp2file Bluetooth Serial Port Profile 2 File is Android application which managing Bluetooth connection between phone and HC-05 or similar Bluetooth module and transmit/receive data from/to file on Android device.

btss2file is writen as Android service to ensure run all the time and also alows starts itself after reboot. It is capable makes multiple bluettoth connection. Principally application periodically read folder and all data what you store in file sends over Bluetooth to Arduino. On oposite direction all data read from Arduino save in file. That means your Android application does not take care about Bluetooth at all, but only simple reads or writes from or to file.

Step 2: Arduino and HC-05 Bluetooth Module

Let's make some basic functional example with blinking LEDs controlled from your Android device.

- Arduino
- HC-05
-1kOhm resistor
-2kOhm resistor

Connect all together according circuit diagram and load following sketch to Arduino.

We will control on board LED (on Arduino nano) by commands from Android, '1' to switch LED on or '0' to switch LED off.

#define RX_PIN 2
#define TX_PIN 3

#define LEDB_PIN 13

#define BTN0_PIN 11

#include SoftwareSerial swSerial(RX_PIN, TX_PIN);

void setup() { Serial.begin(115200); while (!Serial) { } Serial.println("READY");

swSerial.begin(9600);

pinMode(LEDB_PIN, OUTPUT); pinMode(BTN0_PIN, INPUT_PULLUP); }

void loop() { char ch; if(Serial.available() > 0) { ch = Serial.read(); } if(swSerial.available() > 0) { ch = swSerial.read(); } if(ch) { if(ch == '1') { digitalWrite(LEDB_PIN, true); } if(ch == '0') { digitalWrite(LEDB_PIN, false); } if(ch == 'r') { swSerial.print(digitalRead(BTN0_PIN)); Serial.print(digitalRead(BTN0_PIN)); } } }

Step 3: Use Btspp2file

First off all you have to pair your Android with Bluetooth module.
Once is paired open btspp2file application and click to "PAIRED DEVICES" to our one.
Application will connect and starts to read/writes your files in folder showed in "PATH" at bottom of screen.

You can connect to multiple Bluetooth devices, each has own folder with number coresponding with number in "DEVICES" section.

Step 4: Atomate Example

Let's make simple script in Automate. It simply write '0' and '1' to file periodically.
Written file is read by our btspp2file application and contents is send over Bluetooth to Arduino.
And LED is blinking now:)

Step 5: Termux Example

Let's continue with simple example with Termux. It is again simple loop which writes '0' and '1' to file.

You can use Python or any other favorit programing language running in Termux to control Arduino and make amazing projects.

Of course you can read data from Arduino simply by reading rx.txt file.

<p>while [ : ]<br>do
   echo "0" > ~/storage/shared/btspp2file/0/tx.txt
   sleep 1s
   echo "1" > ~/storage/shared/btspp2file/0/tx.txt
   sleep 1s
done</p>
Electronics Tips & Tricks Challenge

Participated in the
Electronics Tips & Tricks Challenge