Controlling an Arduino using an iOS App
and a Bluetooth LE module (HC10/BT05)
Here's a simple Arduino sketch to receive characters from an iPhone app. It's been tested with an HC10/BT05 Bluetooth Module and the following apps:
- HC10 Serial Lite
- LOFI Control
- BLE Joystick
/* simple receiver for iOS apps talking to
BT05/HC10 Bluetooth LE modules
G Payne - 2018
As of June 8, 2018 the following iPhone apps work:
-HC10 Serial Lite,
-LOFI Control and
-BLE Joystick
HC10 Serial Lite is a simple terminal for sending/receiving characters
Arduino BT05/HC10 Module
3.3V VCC
GND GND
11 RX
10 TX
4 - LED with 470R resistor to GND
Open the Serial Monitor after your upload the sketch to see
codes coming from the iOS apps.
The second set of if statements is for the BLE Joystick App codes for the 'X', 'O' and TRIANGLE buttons.
*/
#include <SoftwareSerial.h>
SoftwareSerial BLESerial(11, 10); // RX, TX
char theChar;
int ledPin = 4;
void setup() {
Serial.begin(9600);
BLESerial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (BLESerial.available()) {
theChar = BLESerial.read();
// display the received character in the Serial Monitor
Serial.print("Character received: ");
Serial.println(theChar);
if (theChar == '1')
{
Serial.println(" off");
digitalWrite(ledPin, LOW);
}
if (theChar == '2')
{
Serial.println(" pulse");
for (int i = 1; i <= 5; i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
if (theChar == '0')
{
Serial.println(" on");
digitalWrite(ledPin, HIGH);
}
//------------- Some Codes from BLE Joystick App
if (theChar == 'g') // turn led OFF 'X' button
{
Serial.println(" off");
digitalWrite(ledPin, LOW);
}
if (theChar == 'f') // pulse the led on/off 5 times 'O' button
{
Serial.println(" pulse");
for (int i = 1; i <= 5; i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
if (theChar == 'e') // turn the led ON - TRIANGLE button
{
Serial.println(" on");
digitalWrite(ledPin, HIGH);
}
}
}
BT05/HC10 Bluetooth LE modules
G Payne - 2018
As of June 8, 2018 the following iPhone apps work:
-HC10 Serial Lite,
-LOFI Control and
-BLE Joystick
HC10 Serial Lite is a simple terminal for sending/receiving characters
Arduino BT05/HC10 Module
3.3V VCC
GND GND
11 RX
10 TX
4 - LED with 470R resistor to GND
Open the Serial Monitor after your upload the sketch to see
codes coming from the iOS apps.
The second set of if statements is for the BLE Joystick App codes for the 'X', 'O' and TRIANGLE buttons.
*/
#include <SoftwareSerial.h>
SoftwareSerial BLESerial(11, 10); // RX, TX
char theChar;
int ledPin = 4;
void setup() {
Serial.begin(9600);
BLESerial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (BLESerial.available()) {
theChar = BLESerial.read();
// display the received character in the Serial Monitor
Serial.print("Character received: ");
Serial.println(theChar);
if (theChar == '1')
{
Serial.println(" off");
digitalWrite(ledPin, LOW);
}
if (theChar == '2')
{
Serial.println(" pulse");
for (int i = 1; i <= 5; i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
if (theChar == '0')
{
Serial.println(" on");
digitalWrite(ledPin, HIGH);
}
//------------- Some Codes from BLE Joystick App
if (theChar == 'g') // turn led OFF 'X' button
{
Serial.println(" off");
digitalWrite(ledPin, LOW);
}
if (theChar == 'f') // pulse the led on/off 5 times 'O' button
{
Serial.println(" pulse");
for (int i = 1; i <= 5; i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
if (theChar == 'e') // turn the led ON - TRIANGLE button
{
Serial.println(" on");
digitalWrite(ledPin, HIGH);
}
}
}