Skip to content

Instantly share code, notes, and snippets.

@robherley
Created May 15, 2018 22:44
Show Gist options
  • Save robherley/b1a5093fcbe4ac70eea6dfc44b870395 to your computer and use it in GitHub Desktop.
Save robherley/b1a5093fcbe4ac70eea6dfc44b870395 to your computer and use it in GitHub Desktop.
/**
* Simple Example Communications over Bluetooth using HC-05 Module
*
* Here's an example of the wiring diagram: https://goo.gl/qctNCN
*
* Desktop (thru Arduino IDE)
* - Connect to HC-05 in bluetooth settings
* - Change Port in Tools -> Port to /dev/...HC-05 (NOT the Arduino Port)
* - Open the Serial Monitor (make sure baud rate is 9600)
* - Now you can send the single char commands through there
* Android
* - Arduino bluetooth controller (https://goo.gl/AYasQ1)
* iOS
* - Handy BLE (https://goo.gl/uKrv8F)
*
* Basically, any app will work as long as it can send characters over a serial
* bluetooth connection.
*
*
* @author: Rob Herley
*/
const int LEDPin = 13; // Variable to hold pin value
char input; // Variable to hold bluetooth data
void setup() {
Serial.begin(9600); // Start the Serial Monitor at 9600 baud
pinMode(LEDPin, OUTPUT); // Set the LED pin to output
}
void loop() {
if (Serial.available() > 0) { // Check if Serial communication is active
input = Serial.read(); // Read in a single character to the variable input
Serial.print("Input Character Recieved: ");
Serial.print(input);
Serial.print('\n');
switch (input) {
case 'O': // Turn LED On
Serial.println("Turning on LED");
digitalWrite(LEDPin, HIGH);
break;
case 'F': // Turn LED Off
Serial.println("Turning off LED");
digitalWrite(LEDPin, LOW);
break;
default:
Serial.println("The specified character does not have a case.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment