Control Your Arduino Board Using an iOS Device with the BLExAR App

If you want to control your Arduino board with the BLExAR app, the code and wiring can be found below.

Upload the code below to an Arduino board PRIOR to wiring the HM-10 (CC2541) BLE module.

#include <SoftwareSerial.h>

String strglob= "";
String pin_num_char = "";
int pin_num = 255;
bool analog_bool = false;
bool digital_bool = false;

SoftwareSerial ble_device(0,1);

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  delay(100);
  ble_device.begin(9600);
}

void loop() {

  while (ble_device.available()){
    char ble_char = ble_device.read();    
    if (ble_char == '\n'){
      Serial.println(strglob);
      if (analog_bool){
        pinMode(pin_num,OUTPUT);
        analogWrite(pin_num,strglob.toFloat());
        analog_bool = false;
        pin_num = 255;
      } else if (digital_bool){
        pinMode(pin_num,OUTPUT);
        if (strglob == "1"){
          digitalWrite(pin_num,HIGH);
        } else if (strglob == "0"){
          digitalWrite(pin_num,LOW);
          pinMode(pin_num,INPUT);
        }
        digital_bool = false;
        pin_num = 255;
      }
      pin_num = 255;
      strglob = "";
    } else {
      if (analog_bool == false and digital_bool == false) {
        if (ble_char == 'D'){
          digital_bool = true;
        } else if (ble_char == 'A'){
          analog_bool = true;
        } else {
        }
      } else{
        if (pin_num == 255){
          if (ble_char != 'e'){
            pin_num_char += ble_char;
          } else if (ble_char == 'e'){
            pin_num = (String(pin_num_char).toInt());
            pin_num_char = "";
          }
        } else {
          strglob += ble_char;
        }
      }
    }
  }
  strglob = "";
  delay(10);
}
BLExArduino_wiring_digram.png

Wiring for Arduino Control using Bluetooth and iOS

From here, your Arduino board is controllable using the BLExAR app and your iOS device. Wire an LED or low-power fan to one of the pins and control the component using your iPhone or iPad!

 

See More in BLExAR and Arduino: