When I send text to my HC-05 bluetooth module, the arduino is just interpreting it as some random gibberish.
This is my app inventor code:
Link of my app: MIT App Inventor Gallery
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() {
// Check if data is available to read from Bluetooth module
if (bluetooth.available()) {
String originalSpeech = bluetooth.readString();
Serial.println(originalSpeech);
String speech = removeRepeatedPart(originalSpeech);
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();
}
int pinValue = digitalRead(4);
if(buttonState == pinValue){
bluetooth.println("a");
}
else{
bluetooth.println("b");
}
}
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;
}
Here's what I have already tried:
I tried changing bluetooth.begin(9600) to bluetooth.begin(19200) and bluetooth.begin(4800). But that just makes more gibberish.
This my national level competition project which is due in 2 days. Please help urgently.