****[HC05] Rename the HC05 Bluetooth Module Using AT Command
Connect Arduino Uno to Android Via Bluetooth
Control an Arduino with Bluetooth - Projects
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX, TX
String receivedText = ""; // Variable to store incoming Bluetooth text
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
Serial.println("Bluetooth serial started. Waiting for messages...");
}
void loop() {
// Read characters from Bluetooth
while (BTSerial.available()) {
char c = BTSerial.read();
if (c == '#') { // Make sure the end of every message from mobile app must have "#"
if (receivedText.length() > 0) {
Serial.print("Received: ");
Serial.println(receivedText);
}
} else {
receivedText += c; // Append character to message
}
}
if (receivedText == ""){
digitalWrite(3,HIGH); //switch on LED on pin 3
delay(5000); //5s delay
}
else{
digitalWrite(3,LOW); //switch off LED on pin 3
}
receivedText = ""; // Clear for next message
}