HC - 05 Bluetooth tracking system

Hello everyone,

well first of all I’m new here and not experimented with Arduino ^^

At the moment I’m working on a Project for School, a caddy following you automatically. To track the person it needs to follow, I have chosen Bluetooth technology. I baught the HC - 05 and allready set some things up.
I want to extract the signal strength of the bluetooth signal, sended by the user, with 2 HC - 05 on each side of my caddy. So my 2 HC - 05 will be in master role which I allready configured through AT commands.
Well now comes my problem :

  1. I don’t want to write the commands every single time in the Serial Monitor, so I need them to be send automatically.
  2. I have no idea how to extract the RSSI Signal Strengh of the AT+INQ command. The anwser from HC-05 looks like this : +INQ:2:72:D2224,3E0104,FFBC where the FFBC is the Signal strengh. I thaught of putting it into a string and then get the 4 last characters, but how ? ^^

Well I hope it was clear enough so you could understand what I meant, and hopefully you got some ideas :smiley:

The Code i thaught of was that, but of course it doesnt work xD

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
// Connect the HC-05 TX to Arduino pin 10 RX. 
// Connect the HC-05 RX to Arduino pin 11 TX through a voltage divider.
// 
 
char c = ' ';
 
void setup() 
{
    Serial.begin(9600);
    // HC-05 default serial speed for AT mode is 38400
    BTserial.begin(38400);  
    c = "AT+INIT";
    BTserial.write(c);
    delay(5000);
    c = BTserial.read();
    if (c == "OK")
    {
      c = "AT+IAC=9e8b33";
      BTserial.write(c);
      delay(5000);
      c = BTserial.read();
      if (c == "OK")
      {
        c = "AT+CLASS=0";
        BTserial.write(c);
        delay(5000);
        c = BTserial.read();
        if (c == "OK")
        {
          c = "AT+INQM=1,50,48";
          BTserial.write(c);
          delay(5000);
          c = BTserial.read();
          if (c == "OK") 
          {
            c =  "AT+INQ";
            BTserial.write(c);
          }
        }
      }
    } 
}
 
void loop()
{
 
    // Keep reading from HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
    {  
        c = BTserial.read();
        Serial.write(c);
    }
 
    // Wait for the HC05 to anwser OK then send again the RSSI test 
    if (c == "OK")
    {
        delay(5000);
        c =  "AT+INQ";
        BTserial.write(c);  
    }
 
}

The error message was this:

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino: In function 'void setup()':

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:16:7: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:20:14: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:22:9: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:26:16: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:28:11: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:32:18: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:34:13: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:38:20: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:40:15: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino: In function 'void loop()':

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:59:14: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

D:\\Documents\Lycée\Projet SI\Programm Arduino\testForString\testForString.ino:62:11: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

Thank you for your time :slight_smile:

variable c can store a single char..... not a string. Use array of char.... or string_type

Hey,
thank you for the fast answer.
It now works properly, but I have encountered an other problem. As the RSSI Signal Strengh given from the HC 05 modul is not very accurate I need to calculate the average of a few measurements. Here is what I thaught of, but it doesnt pront my Rssi String…

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX


String Signal = " ";
String Rssi = " ";



[setup...]

void loop()
{


BTSerial.write("at+inq\r\n");

  Signal = " ";
  //While HC 05 hastn anwsered, wait for an anwser
  while (Signal.startsWith(" ",0)){
  if (BTSerial.available()) {
    Signal = BTSerial.readString();
    Serial.print(Signal);
    
  }
 
    for (int i = 28; i < 32;i++){   //Put the a'th value of the Rssi String to the i'th value of the Signal string
      for (int a = 0; a < 4;a++){
      Rssi.setCharAt(a,Signal.charAt(i));
      a++;
      }  
    }
    Serial.print(Rssi);

Well the problem is the Rssi.setCharAt(a,Signal.charAt(i));
You have an idea how I could do this ? ^^

for (int i = 28; i < 32;i++){ //Put the a’th value of the Rssi String to the i’th value of the Signal string
for (int a = 0; a < 4;a++){
Rssi.setCharAt(a,Signal.charAt(i));
a++;
}
}

Two loops ?? i dont follow…
If the idea is to copy 4 chars ? try “Rssi=Signal.substring(28,32);”

=>stringtoInt (unsigned) , repeat N timss while adding to a long , avarage …

Hey,

yes two loops, because I need 2 variables, one for the position of the RSSI Strengh in the Signal string : +INQ:2:72:D2224,3E0104,FFBC and one for the position in the Rssi string.
So in this case it should put the 28'th char of the Signal String, so the first F, at the 0'th place in the Rssi String, then the 29'th char of the Signal String, so the second F, at the 1'th place in the Rssi String, the 30'th at the 2'th, the B and the 31'th at the 3'th, the C.
Thats why I wanted to use 2 "for loops".

Thank you sooo much for your advise with substring, it works ! :smiley:

Hey it’s me again,

I have now what I wanted, but as I said before, I need an accurate value of the Signal strengh so I want to calculate the averange on 50 mesurements ( I tryed with 5 in my programm). I got it to work how I want but some times it sends me shitty values. As you may see here (green are the correct values, the one I need, and red is the shitty thing xD) Link to the image

Here is the code, may someone please be able to tell me why some of the mesurements went that wrong ? ^^
And when I earase the number of muserements to 50, it totally fcks up and i get no values… why ? ^^

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

String Setup_test = " ";
String Signal = " ";
String attempt = "OK\r\n";
String Rssi = " ";
int nombre_de_mesure = 5; // A changer ici et plus bas dans inqm!
int laenge = ' ';
int a;
long somme = 0; 
long amplitude_du_signal = ' '; 
long fixe = 0;


void setup()
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
  BTSerial.write("at+reset\r\n");
  Setup_test = BTSerial.readString();
  while (Setup_test != attempt){
     Setup_test = BTSerial.readString();
  }
  Serial.print(Setup_test);
  BTSerial.write("at+cmode=1\r\n");
  Setup_test = BTSerial.readString();
  while (Setup_test != attempt){
     Setup_test = BTSerial.readString();
  }
  Serial.print(Setup_test);
  BTSerial.write("at+inqm=1,5,48\r\n");    //nombre_de_mesure a changé ici egalement
  Setup_test = BTSerial.readString();
  while (Setup_test != attempt){
     Setup_test = BTSerial.readString();
  }
  Serial.print(Setup_test);
  BTSerial.write("at+init\r\n");
  Setup_test = BTSerial.readString();
  while (Setup_test != attempt){
     Setup_test = BTSerial.readString();
  }
  Serial.print(Setup_test);
}

void loop()
{


BTSerial.write("at+inq\r\n");
  Signal = " ";
  fixe = 0;
  a = 0;
  // Le temps que HC 05 n'a pas repondu attend une reponse
  while (Signal.startsWith(" ",0)){
  if (BTSerial.available()) {

    Signal = BTSerial.readString();
    Serial.print(Signal);
    laenge = ((Signal.length()-2)/(nombre_de_mesure));
      for (int i = 0; i < (nombre_de_mesure+1);i++){
        Rssi = Signal.substring((i*laenge)+(laenge-6),(i*laenge)+laenge);
        char rssi[5] = {Rssi.charAt(0),Rssi.charAt(1),Rssi.charAt(2),Rssi.charAt(3)};
        somme = strtol(rssi, NULL, 16);  //Convertir le contenu du String Rssi (4 lettres / chiffres ex: FFBC) en DECimal (convertir de hexa en decimal) puis mettre le long somme à la valeur du String Rssi
        fixe = fixe + somme; //Faire la somme des differentes valeurs de signal Rssi      
        a++;
//        Serial.print(Rssi);        
    }
  }
 }
     amplitude_du_signal = fixe/a;
     Serial.print(amplitude_du_signal);

    }

Thank you in advence :smiley:

Looks like some values are far off, which CAN happen in radio comm. Instead of average many values, use the median. I guess less than 10 readings will do.

We are doing the same project as yours , however we are having a hard time configuring the hc05 . May we know how you configure your hc05 (what state and parameters?) and the pin connection from the bluetooth to arduino thanks

We are stuck at the part that the serial monitor shows Enter AT commands: and no rssi values are showing