#include <SoftwareSerial.h>
#include <Stream.h>
#include <Print.h>
SoftwareSerial hm10(4, 5); // RX, TX pins of Arduino connected to RX, TX pins of HM-10 module
#define blePo 7
bool flag = true;
void setup() {
Serial.begin(9600);
hm10.begin(9600); // HM-10 module baud rate
delay(1000);
pinMode(blePo,OUTPUT);
Serial.println("Sending AT commands to change Bluetooth device name...");
// hm10.write("AT+NAMEKUNAL\r\n"); // Replace with the name you want
delay(500);
digitalWrite(blePo,HIGH);
Serial.println("Bluetooth device name changed successfully!");
}
void loop() {
// Your main code goes here
//
String name = "AT+NAME";
if(hm10.available() && flag){
Serial.println("IN");
//flag = false;
while(hm10.available()){
name += char(hm10.read());
// hm10.write(Serial.read());
}
}
delay(1000);
if(name.length() > 8){
// flag = false;
Serial.println("HII");
char buf[30];
name.toCharArray(buf, name.length()+1);
Serial.println(buf);
digitalWrite(blePo,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
hm10.end();
delay(1000);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(blePo,HIGH);
hm10.begin(9600);
delay(15000);
hm10.write(buf);
delay(1000);
Serial.println(buf);
}
}
This code seems to be attempting to receive a new Bluetooth device name from the Bluetooth HM-10 and then change the name of the HM-10 Bluetooth module accordingly. However, there might be some issues in the code that could be affecting its functionality. plz suggest me changes..