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.
