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. The wiring is for an HM-10 (CC254x) board, and the demonstration later in the tutorial uses an RGB LED (wired separately). Also, a kit has been assembled that includes these three components and is linked to the right.
NOTE: Be sure to upload the control code below to an Arduino board PRIOR to wiring the CC254x BLE module to the board. The user can also change the pin designation ble_device(A,B) to any pins on the Arduino (A = 3, B = 4; for example), then the user can upload code while it is wired.
#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); }
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:
This is the second entry into the tutorial series centered around the MakerBLE Arduino board. Using the BLExAR iOS app again, we are able to monitor the incoming data from the MakerBLE board, plot the values, and save them to a comma-separated value (CSV) file. The data being sent is read from a BMP280 sensor over the I2C port by the MakerBLE board. Temperature, atmospheric pressure, and approximate altitude were all sent over the BLE connection with an iPhone.