I am working on my electronic project which contains an app which receive and transmit bluetooth data.my transmition part is working properly but I am facing problem in receiving section.can any one plz help me to solve the problem.I am sharing the block image of receiving section the global variable used in the codes are already initialised
I am a beginner in Arduino and mit app inventor.I just made a code to transmit data given in serial monitor of Arduino ide to the hc05.and here is the Arduino code that I am using for testing the app
void loop() {
// Check if data is available from the HC-05 Bluetooth module
if (hc05.available()) {
String receivedData = hc05.readString(); // Read the entire string from Bluetooth
Serial.print(receivedData); // Print the received data to the Serial Monitor
}
// Check if data is available from the Serial Monitor
if (Serial.available()) {
String inputData = Serial.readString(); // Read the entire string from Serial Monitor
hc05.print(inputData); // Send the entire string over Bluetooth
}
}
Dear @EDWIN_JAMES,
as @Patryk_F has already said, your Arduino code is missing the correct string terminator (i.e. the ASCII character "linefeed", 0x0A, or decimal 10). To obtain this your last sending to the app via BT shall be made by using a hc05.println(); and not just with a .print();
You can refer to very detailed instructions by reading the FAQ from @ABG :
Moreover, to be sure that your Arduino is sending data correctly, you could, at the beginning, use a ready made app, like Serial Bluetooth Terminal that you can download free from Google Appstore. Once you are sure that the communication from Arduino to your Android device is working fine, then you can go on with your app. Last, but not least, remember that you shall cross Tx and Rx piins between HC05 and Arduino CPU board.
Best wishes
EDIT here below a super simple example : BT_to_Arduino.aia (26.3 KB)
Dear @EDWIN_JAMES ,
please pay attention to what @ABG has said about the delimiter (i.e. its settings in your app).
Theoretically your blocks seem correct (but to be 100% sure I should have a hardware 100% equal to yours). Anyway, one additional hint is related to the text comparison: typically it's better not to search for an "exact" equality, because a blank (space) or a hidden character can foolish the comparison, but you can just search for a text contained, like in my example in the aia annexed to my previous post.
Moreover, to avoid a mismatch due to lowercase or uppercase characters, I do a conversion in uppercase of everything received via BT.
Have you tried my example (annexed aia and ino) ? Or, at least, have you had a look into them ?
Yes I referred you code but not tried it because I only get my lab facility and equipments Monday,Thursday and friday.I will check it today itself thankyou for helping me
The delimiter is normally set directly in the Designer page:
(To this purpose I've added the .aia in my previous post)
Anyway if you want to add it as a block, you could use this one in the Screen1 Initailize event.
Best wishes.
I made all the corrections.I tested my bluetooth module with smartphone bluetooth serial communication app.I am sharing both screen shot of my Arduino ide serial monitor and app screen here the communication is perfect.I also changed Arduino code (print to println).Then I connected my app with ai companion and tested it with Arduino ide serial monitor.when i click on data transmit buttons data is reaching in monitor.But when I send data to app nothing is happening.I am sharing my app aia file below.plz help me
I right clicked on get global data and select do it option then a comment screen poped from there then I send data through Arduino ide serial monitor after connecting it with companion.nothing is showing in it .Is there any problem cause I am minimizing mit app inventor and sending data through Arduino ide then checking it .
Nice to read that you solved (and sorry by having missed your recent posts).
You've solved by using the boolean equality, but my last hint, anyway, is that the next time you want to compare texts, remember to avoid to search the exact equality but to use the "if contains" block (as I said in one of my previous posts).
And by converting in uppercase anything received, you'll be sure that a mismatch caused by upper/lower cases will be avoided.
Best wishes for your next app !
When using the text CONTAINS test, be careful that you don't get false positives from testing input '12' if it CONTAINS '1'. You will get a true result, but maybe you also intended to test for '12'. Test for '12' first.
The failure of the text COMPARE tests compared to the success of the green '=' tests bothered me.
I suspect there are invisible characters like \r riding along in the input stream that cause the text COMPARE to fail, but are filtered out by the green '=' test in its numeric conversion.