Hossein Jamshidi
Published © GPL3+

Easy Android UI for Arduino Project

Create an Android App for your Arduino projects using Bind, a library supporting BLE, Wi-Fi, classic Bluetooth, and USB-OTG.

BeginnerProtip1 hour171
Easy Android UI for Arduino Project

Things used in this project

Hardware components

ESP32
Espressif ESP32
Any ESP32 with WiFi, classic Bluetooth, or BLE is. Other Arduino boards are also fine. Even if there is no connectivity available, you can still use USB-OTG.
×1

Software apps and online services

BindCanvas from GooglePlay for free
Arduino IDE
Arduino IDE

Story

Read more

Code

Bind_LED_Controller.ino

Arduino
#include "Bind.h"
#include "BindUtil/BindOverBLE.h"
BleStream bleStream;
Bind bind;
BindButton buttonOn, buttonOff;
const int ledPin = LED_BUILTIN;
void buttonOn_pressed() {
  digitalWrite(ledPin, HIGH);
}
void buttonOff_pressed() {
  digitalWrite(ledPin, LOW);
}

void addbuttonOn() {
  // Set the Button's position on the screen.
  buttonOn.x = 30;
  buttonOn.y = 150;
  // Set the Button's text label.
  buttonOn.setlabel("ON");     // button label
  buttonOn.fontSize = 23;      // The Button size is relative to the Font size.
  buttonOn.textColor = BLACK;  // Text color
  buttonOn.backColor = GREEN;  // button color
  // Check this for cmdId: https://h1jam.github.io/Bind/class_bind_button.html
  buttonOn.cmdId = BIND_ADD_OR_REFRESH_CMD;
  // Set the callback function for the Button 1 object.
  buttonOn.setCallback(buttonOn_pressed);
  // Synchronize the buttonOn object with BindCanvas.
  bind.sync(buttonOn);
}

void addbuttonOff() {
  // Syncing Button 2, check addbuttonOn for more information.
  buttonOff.x = 30;
  buttonOff.y = 200;
  buttonOff.setlabel("OFF");
  buttonOff.fontSize = 23;
  buttonOff.textColor = BLACK;   // Text color
  buttonOff.backColor = YELLOW;  // button color
  buttonOff.cmdId = BIND_ADD_OR_REFRESH_CMD;
  buttonOff.setCallback(buttonOff_pressed);
  bind.sync(buttonOff);
}

// This function gets called every time you connect.
void onConnection(int16_t w, int16_t h) {
  addbuttonOn();
  addbuttonOff();
}

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);

  bleStream.begin("YOUR_DEVICE_NAME", bind);
  bind.init(bleStream, onConnection);
  // onConnection is the function defined above.
}

void loop() {
  // Nothing is needed here for BIND over BLE and WIFI.
  delay(1000);
}

Credits

Hossein Jamshidi
1 project • 0 followers
Hossein is a multidisciplinary software developer knowing electronics and a Master’s degree in Mechanics.

Comments