Unable to receive proper communication from the app to arduino

I have created an app to control a robotic arm via Bluetooth (HC-05) and Arduino. The following is the screenshot showing a block related to the switch.

When the switch is on it has to send "O" and when the switch is off, it has to send "N". But on every toggle of the switch I am getting different characters starting from " % + . 1 4 7 : = ? each on every toggle, on my serial monitor of Arduino. In the end, I am continuously receiving only ? and how manytimes I do the toggle of the switch, there is no change.

If I am sending any message from the Ardunio to my app, the following error messages are received in the app.

Following are the states of ARM switch:

I am using software serial to connect both the computer serial and the HC-05 serial to Arduino. I have tried two different communication rates 9600 and 38400. If I give 38400 as the baud rate for both the serial and software serial, only then I am at least some message. In all the other cases there is no communication at all. Please help by letting me know what is the mistake I did and how to rectify it. If more information is needed, I shall provide.

Show what you get in the terminal on your computer when you send data from the app to arduino. Show also the arduino code.

At the last I continuously receive ? no matter what.

Following is the arduino code:armcode.txt (10.6 KB)

These are the additional images showing the data received after the 7.

I see some inconsistency in the code. What arduino do you use? To which pins do you have the bt module connected?

The rule is that the terminal and bluetooth cannot work on the same serial port. I see that bluetooth should be on pins 3 and 4. Bluetooth is set to a baud rate of 38400. Unfortunately, there are modules that have the factory set to 9600. Change the value to 9600. The second thing is the uart for the terminal is set to 9600 in the code, while on the screens I can see that you are using 38400.

If I make the baud rate 9600, there is no communication received. I have connected the Bluetooth to pins 3 & 4. I am using Arduino UNO.

If there is no communication at 9600, leave the BT speed as is. Only change the speed in the terminal window to 9600.

Export your .aia file and upload it here.

This is the aia file.
Coconut_Tree_Sing.aia (12.4 KB)

I have done changing the terminal speed to 9600. Still no use. Could you please tell me if my Arduino code correctly getting the Bluetooth serial.

Try it:
Coconut_Tree_Sing (2).aia (12.3 KB)

You should be properly receiving data from arduino.

Now code from arduino:

This line initializes the communication speed with the terminal at 9600, so do not use a different speed on the terminal.

Serial.begin(9600); // Initialize serial monitor

This line initializes the communication speed with the BT at 38400. If the speed is correct, you will see "Hello world" in the label.

bluetooth.println("Hello, world?");

As for the data sent from the app to arduino, it does nothing except being displayed in the terminal.

I used 38400 in the terminal used the same in the serial.begin. With commands from the serial monitor, it is working without any issues. The control is fine. The only issue is with the bluetooth transmission/reception.

Anyways, i will your app updated and see.

Now I understood my issue(one of). I have used bluetooth.available instead of bluetooth.read command(My bad.....). But still one problem is there.

I am receiving ascii characters instead of receiving letters like w, x, y, z.

can someone help me with that.

I do not know what you're talking about. Preferably show screenshots or photos to better give feedback. Without it, it's hard to help. I have to guess what it looks like at the moment, instead of just seeing it.

I think you're talking about it. Yes I missed it.

char ch=bluetooth.available();

I see in your code for arduino 9600, not 38400. So I don't know what you're talking about. After my modifications I think your blocks for appinventor are correct. Chars are sent correct. The problem is with your arduino code not properly processing the received data. That's why I think now you should seek help on the arduino forum and tweak your code.

I have tried different speeds. But I ensured that I have used the same speed in the serial monitor as that was used to initialize using Serial.begin(). That was not a problem.

If I toggle the ARM switch to send 'O' (capital o), I receive 79, if I send 'N' (capital n), i receive 78.

I better do that.

This one I have used properly.