Send second to Arduino via Bluetooth+Android+App Inventor 2

Ok, im trying to send the second to my arduino (mini pro) from my android phone. the bluetooth module is a hc-06.

The problem is: when its sending, for ex. 30 (seconds), the arduino outputs on the serial monitor "51
48". i cant see a number below 40.
Arduino Code.

#include <SoftwareSerial.h>

SoftwareSerial mySerial( 6, 5); // RX, TX
int timeAndroid;

void setup() {
   Serial.begin(9600);
   mySerial.begin(9600); 
}

void loop() {
 //Serial.println("Hello! Im a Serial"); 
 //mySerial.println("Hello! Im a bluetooth module!");
  timeAndroid = mySerial.read();
 
    if(timeAndroid != (int)-1) {
  Serial.println(timeAndroid);
    }
}

AI2 blocks

AI2 GUI

Thanks for any help :slight_smile:

~Straw

The problem is: when its sending, for ex. 30 (seconds), the arduino outputs on the serial monitor "51
48". i cant see a number below 40.

What character corresponds to the value 51 in the ASCII table? To 48?

The read() method returns a byte or character in the low order byte of the int value. The high order byte is there only so that the method can return an error. An error will only occur if you try to read a byte/char from the serial buffer when there is none to read.

Use Serial.available() before Serial.read() so the function doesn't need to tell you that you are an idiot, and then you can store the returned value in a byte or char. If you store it in a char, you'll see much different behavior when you print it.

Of course, you are using read() because you think it reads an entire string of characters and reforms the int that you sent. It does not. But, parseInt() does.

Ok, thanks :slight_smile:
havent done really that much with the ascii table, better im gonna do that.

~Straw