Arduino+Bluetooth and Android Communication Character Unrecognized

Hello, I am new to arduino and I am trying to make a 3x4 Keypad for Android Phones. I tried the sample code for SoftwareSerial which is

/*
  Software serial multple serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit: 
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)
 
 created back in the mists of time
 modified 9 Apr 2012
 by Tom Igoe
 based on Mikal Hart's example
 
 This example code is in the public domain.
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX
//int inputSwitch = 7;
void setup()  
{
 // Open serial communications and wait for port to open:
  Serial.begin(38400);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
   
  //set input
 // pinMode(inputSwitch, INPUT);
  
  
}



void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
    
/* if(digitalRead(inputSwitch)== LOW){
  Serial.println("Alryt!");
  }*/
}

I adjusted the baud rate to 38400 from the default 57600

The code is supposed to communicate with the android phones through a Bluetooth terminal(I used an app called Bluetooth SPP).
It is supposed to have the ability to send or receive texts or characters from the phone or vice versa. It was able to that but the characters sent from each other where unrecognised. This is the link of the image of the output on the Serial Monitor
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash4/481442_2569654298674_1193692205_n.jpg

And this what happens in on Android Phone.
https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-snc7/430874_2569657538755_1590168018_n.jpg

What is wrong? Is it the code or the ckt? TX is to D3 and RX is to D2.. :.

The read() methods of HardwareSerial and SoftwareSerial returns an int. You are then sending that int as binary data to the Serial Monitor which expects text. You are then surprised when the data is "misinterpretted"?

Im sorry that was from the other code that I was trying here is code that I have used

/*
  Software serial multple serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit: 
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)
 
 created back in the mists of time
 modified 9 Apr 2012
 by Tom Igoe
 based on Mikal Hart's example
 
 This example code is in the public domain.
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()  
{
 // Open serial communications and wait for port to open:
  Serial.begin(57600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
   mySerial.write(Serial.read());
}

Im sorry that was from the other code that I was trying here is code that I have used

And how is that different? The read() methods still return ints, and you are still sending them as binary data (that's what write() does, and how it differs from print()).

What can you suggest? As I have said I'm new to arduino.. I do not know a lot of its syntaxes.

What can you suggest?

I've already made (a subtle) suggestion. The Serial.available() method (as well as the SoftwareSerial.available() method) determines if there is anything to read. If the calls to the read() methods always happen inside if(Serial.available()) blocks, the value returned by Serial.read() (and SoftwareSerial::read()) can be stored in a char.

DO THAT.

Then use the print() methods NOT the write() methods to output the data.

I'll try that thanks

I replaced all the read() to print all the sent data from the android where shown as numbers while the data send from the arduino are still diamonds with question mark...

I replaced all the read() to print all the sent data from the android where shown as numbers while the data send from the arduino are still diamonds with question mark...

Your code now looks like?

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX
//int inputSwitch = 7;
void setup()  
{
 // Open serial communications and wait for port to open:
  Serial.begin(38400);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
   
  //set input
 // pinMode(inputSwitch, INPUT);
  
  
}



void loop() // run over and over
{
  if (mySerial.available())
    Serial.print(mySerial.read());
  if (Serial.available())
    mySerial.print(Serial.read());
 }
  if (mySerial.available())
    Serial.print(mySerial.read());
  if (Serial.available())
    mySerial.print(Serial.read());

I give up. You insist on sending ints to the output port, instead of chars.

  if (mySerial.available())
  {
    char someChar = mySerial.read();
    Serial.print(someChar);
  }
  if (Serial.available())
  {
    char someChar = Serial.read();
    mySerial.print(someChar);
  }

Thanks! I told you that I am still new to this stuff. But the data that was sent from the android was these "?xþxþxàxþø" while I have input "Hello"

kelvs24:
Thanks! I told you that I am still new to this stuff. But the data that was sent from the android was these "?xþxþxàxþø" while I have input "Hello"

Sounds like a Baud Rate mismatch.

That's one of the first thing that I have thought. I tried that before you told about me the char inputs. I'll try to change it

Got It! The Baud Rate is 9600. Is it possible that android phones have different baud rate?

kelvs24:
Got It! The Baud Rate is 9600. Is it possible that android phones have different baud rate?

Is there a physical connection between the Android and Arduino, or is it communicating through Bluetooth? If the latter, the baud rate of the Android doesn't matter, it's whatever the Bluetooth Module is set to.

Arrch:

kelvs24:
Got It! The Baud Rate is 9600. Is it possible that android phones have different baud rate?

Is there a physical connection between the Android and Arduino, or is it communicating through Bluetooth? If the latter, the baud rate of the Android doesn't matter, it's whatever the Bluetooth Module is set to.

it is communicating through Bluetooth...