Arduino Arduino UNO BlueSMiRF Bluetooth LED LED control RFCOMM RoboRemo button
// Control Arduino LED via Bluetooth
// using RoboRemo app
// www.roboremo.app
// Hardware setup:
// BT module Arduino
// GND ------- GND
// VCC ------- 5V
// TX-O ------ pin2
// RX-I ------ pin3
// Arduino UNO already has an LED attached to pin 13
#include <SoftwareSerial.h>
int bluetoothTx = 2;
int bluetoothRx = 3;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
int led = 13;
char cmd[100];
int cmdIndex;
void exeCmd() {
// "led" is the led id
if(strcmp(cmd, "led 0")==0) digitalWrite(led, LOW);
if(strcmp(cmd, "led 1")==0) digitalWrite(led, HIGH);
}
void setup() {
delay(500); // wait for bluetooth module to start
bluetooth.begin(115200); // Bluetooth default baud is 115200
bluetooth.print("$");
bluetooth.print("$");
bluetooth.print("$"); // enter cmd mode
delay(250);
bluetooth.println("U,9600,N"); // change baud to 9600
bluetooth.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
cmdIndex = 0;
}
void loop() {
if(bluetooth.available()) {
char c = (char)bluetooth.read();
if(c=='\n') {
cmd[cmdIndex] = 0;
exeCmd(); // execute the command
cmdIndex = 0; // reset the cmdIndex
} else {
cmd[cmdIndex] = c;
if(cmdIndex<99) cmdIndex++;
}
}
}