I am sending text to my hc05 bluetooth module as string but when i see the text in arduino, it is all some random gibberish

Yes I have... Thanks for the code I will check it

-1 gives me some errors and bugs in the app

I have checked the connections and everything else... That doesn't seem to be the problem :confused:

Yes... Speech recognition is working perfectly

The connections are perfect.. i have checked :confused:


I used your code, what you see in the serial monitor is nice to meet you (but in gibberish version). What can I do now?

@uskiara I modified code you shared a bit as you can see in the picture because what you shared was not working. I think I was able to solve the problem of gibberish text. But now I am facing another problem, all the text in being printed in one line. How can I change that? Also, if possible can you combine the modifications I shared with my original code and share with me because I am quite a beginner and am not able to do so

This is the link of a video of how it is working: WhatsApp Video 2023-11-28 at 15.26.58_208d61a2.mp4 - Google Drive

Also, what I thought from the conclusion I drew from this change was that problem was with bluetooth.readString(); it had to be changed to bluetooth.read(). That's what you and @ChrisWard suggested earlier. But now when I am trying to change it, arduino ide is showing this error:

Just updating my situation @uskiara @ChrisWard . I removed a piece of code given below from my arduino code and now it is working perfectly. Just that what I removed is really important and I need to include it in my code. But the moment I include the code, it starts malfunctioning.
This is what I removed:

int pinValue = digitalRead(4);
if(buttonState == pinValue){
bluetooth.println("a");
}
else{
bluetooth.println("b");
}

This is my arduino code:

#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>

// Define the TX and RX pins for the SoftwareSerial library
SoftwareSerial bluetooth(2, 3); // RX, TX

// Define LCD_I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2);

void setup() {
// Start the serial communication with a baud rate of 9600
Serial.begin(9600);

// Start the Bluetooth communication with the HC-05 module
bluetooth.begin(9600);

// Start the lcd module
lcd.init();
lcd.backlight();
//Configure the button
pinMode(4, INPUT_PULLUP);
}
String comparison = "ffkggjhgjgkugkjghjgyug";
int buttonState = 0;
void loop() {
String originalSpeech;
// Check if data is available to read from Bluetooth module
if (bluetooth.available()) {
originalSpeech = bluetooth.readString();
Serial.println(originalSpeech);
String speech = removeRepeatedPart(originalSpeech);
Serial.println(speech);
char message[speech.length() + 1];
speech.toCharArray(message, sizeof(message));

  char* token = strtok(message, " ");

  while (token != NULL) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(token);
    delay(1000);
    token = strtok(NULL, " ");
  }
  delay(1000);
  lcd.clear();
}

}
String removeRepeatedPart(String input) {
int length = input.length();

// Iterate through the string to find the repeated part
for (int i = 1; i < length; i++) {
String prefix = input.substring(0, i);
String suffix = input.substring(i, 2 * i);

// Check if the prefix and suffix are the same
if (prefix.equals(suffix)) {
  // Remove the repeated part from the original string
  return input.substring(i);
}

}

// If no repeated part is found, return the original string
return input;
}

Please help me include the code I shared... :pray:t2:

I think the problem is that I a constantly sending 'b' values to the hc05 so when the app sends string to the hc05, it causes problem because two values are sent at the same time. Can you please update the code accordingly and help.

Basically, I am using this piece of code to check if the push button is pressed. If the push button is pressed, arduino sends 'a' to hc05, otherwise it sends 'b' to hc05. The app checks if the last value sent to the hc05 is 'a' or 'b'. If 'a', it turns on the mic, otherwise, if 'b', it does not turn on the mic.

With this info, can you pls help me :pray:t2:

Thanks for your help @uskiara @ChrisWard ... I understood the problem, Now I was able to solve the problem. Thanks :slight_smile:

Dear @Aryaman_Aggarwal, happy that you solved. Unfortunately I've been out today and I'm reading only now :upside_down_face:
Best wishes for your competition !
Cheers.

Thanks :slight_smile:

Please tell us your solution Aryaman

Hi @ChrisWard , sorry for the late reply... I forgot to check the community website. To solve the problem , I modified the code so that it sends a only once when the button is pressed and b only once when the button is released. This solved the problem for me :slight_smile:

2 Likes

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