How to change Bluetooth HM-10 name by receiving new name from Bluetooth

#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..

Your post is barely coherent, but I think that is correct, and much the same can be said for the wiring. IF you are trying to change the name of one Bluetooth by receiving the new name wirelessly, you need to bear in mind that you cannot be in comms mode and AT mode at the same time. After you question why you would want to do this, you might be able to write a programme that receives the new name via Bluetooth as data, then momentarily interrupts the power to Bluetooth, thereby putting it into AT mode. You may then send the AT+NAME command using the received variable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.