Bluetooth - whole string receive problem

Hey Guys!
Currently trying to setup a basic bluetooth connectiong/APP using the arduino mega and a HM05 module.

Iam using softwareserial(issue was also existing using hwSerial)

Bascially the arduino is supposed to send a string "unlocked" or "locked" - this works 70% of the time - sometimes however it messes up half the string to something like "nlocked" or "ocked".

Hope you guys have a pointer where to look - attaching both app inventor and code below

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); //pin number. RX, TX

#define ledPin 7
int state = 0;
void setup() {  
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  mySerial.begin(9600);

}
void loop() {
  if(mySerial.available() > 0){ // Checks whether data is comming from the serial port
    state = mySerial.read(); // Reads the data from the serial port
 }
 if (state == '0') {
  digitalWrite(ledPin, LOW); // Turn LED OFF
  mySerial.println("locked"); //Send back the string "locked"
 }
 else if (state == '1') {
  digitalWrite(ledPin, HIGH);   //Turn LED ON
  mySerial.println("Unlocked"); // Send back the String "Unlocked"
  }
 }

looks like the image wont show up, attaching instead.

Gedefims:
Bascially the arduino is supposed to send a string "unlocked" or "locked" - this works 70% of the time - sometimes however it messes up half the string to something like "nlocked" or "ocked".

That reads as if your problem is with sending data rather than receiving it.

See this Simple Image Upload Guide

...R

What happens if you use the built-in serial monitor?

Assuming it's an Android phone and standard Bluetooth --
try a few of the many Bluetooth terminal apps available.

Good luck with your project.

73, N1GNV

I think this is actually an MIT App Inventor question, not an Arduino question as it seems the Arduino portion is working as expected.