Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Repository files navigation

ArduinoConnect

Build Status

Connecting Android and Arduino using bluetooth with Serial communication

Feature

  1. Easy to use
  2. Show paired and unpaired bluetooth device
  3. Can pairing bluetooth device
  4. Can send string to arduino with Serial
  5. Can receive string from arduino

Tested on :

  • Android 4.1.2 and Arduino with HC-05 module

Permission :

This application using bluetooth permission to connect to Arduino. This permission is added on library

<uses-permissionandroid:name="android.permission.BLUETOOTH"/>
<uses-permissionandroid:name="android.permission.BLUETOOTH_PRIVILEGED"/>
<uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/>

How to use :

  1. Add this to your root build.gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
  1. Add dependency
 compile 'com.github.kido1611:ArduinoConnect:-SNAPSHOT'
  1. Add line to your activity
publicclassMainActivityextendsAppCompatActivityimplementsArduinoConnectCallback{
privateArduinoConnectmArduinoConnect;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
...
mArduinoConnect = newArduinoConnect(this, getSupportFragmentManager());
mArduinoConnect.setCallback(this);
...
mArduinoConnect.showDialog(); // Show dialog bluetooth list to connectmArduinoConnect.sendMessage("Hello"); // Send string to arduino
}
@OverrideprotectedvoidonActivityResult(intrequestCode, intresultCode, Intentdata) {
super.onActivityResult(requestCode, resultCode, data);
...
if(mArduinoConnect!=null) // Must added to activitymArduinoConnect.onActivityResult(requestCode, resultCode, data);
}
@OverrideprotectedvoidonDestroy() {
super.onDestroy();
...
if(mArduinoConnect!=null) // Recommended to add, to reduce memory leakmArduinoConnect.disconnected(); // Disconnecting Android and Arduino
}
privatevoidshowLog(Stringmessage){
Log.d("ArduinoConnect", message);
}
@OverridepublicvoidonArduinoConnected(BluetoothDevicedevice) {
showLog("Connected");
}
@OverridepublicvoidonArduinoConnectFailed() {
showLog("Failed to connected");
}
@OverridepublicvoidonSerialTextReceived(Stringtext) { // Function to receive Serial text from ArduinoshowLog(text);
}
@OverridepublicvoidonBluetoothDeviceNotFound() {
showLog("Bluetooth device not found");
}
@OverridepublicvoidonBluetoothFailedEnabled() {
showLog("Bluetooth device not enabled");
}
}

Todo :

  1. Show section paired and unpaired
  2. Still imagine

License

The MIT License (MIT)
Copyright (c) 2016 Muhammad Abdusy Syukur
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Connecting Android and Arduino using bluetooth with Serial communication

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages