Get confusion when sending and receiving data between 2 arduino boards

I m doing a project to communicate two arduino boards via bluetooth modules.
Code Master

#include <SoftwareSerial.h>

#define BT_SERIAL_TX 10

#define BT_SERIAL_RX 11

SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);

int potpin = A0;

int val;
int gt;
int val1=0;

void setup()

{

Serial.begin(9600);

BluetoothSerial.begin(9600);

}

void loop()

{

val = analogRead(potpin);
if(val!=val1){
gt = map(val, 0, 1023, 0, 179);
//val=5;
BluetoothSerial.print(gt);
Serial.println(gt);
val1=val;
}
delay(100);

}

Question 1: IF val= 150, does arduino send instantly 150 or send each number as 1 and 5 and 0.
Do I need to send highbyte and lowbyte of 150
Code slave

#include <SoftwareSerial.h>

#define BT_SERIAL_TX 10

#define BT_SERIAL_RX 11

SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);

#include <Servo.h>
const byte numChars = 2;
byte receivedChars[numChars];
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
static boolean recvInProgress = false;
boolean newData = false;
char rc;
char rc2=0;
Servo myservo;
void setup()
{
Serial.begin(9600);
BluetoothSerial.begin(9600);
}
void loop() {
 // recvOneChar();
 // showNewData();
 if(BluetoothSerial.available() > 0)
    rc = BluetoothSerial.read();
    receivedChars[ndx] = rc;
    Serial.print("This just in ... ");
   Serial.println((char*)receivedChars);
   delay(1000);
}

Question 2: When I monitor the received data in monitor, I saw it displays each digit as 1 and 5 and 0. Can any one help me to combine each digit together as the received data

if(val!=val1){

Spaces would improve the readability of this code.

Question 1: IF val= 150, does arduino send instantly 150 or send each number as 1 and 5 and 0.

It instantly buffers '1', '5', and '0'. As time permits, it sends '1', '5', and '0'.

Do I need to send highbyte and lowbyte of 150

Not necessarily. What you do need to do is send some kind of end-of-packet marker, like carriage return and linefeed, which is easily done by using println() instead of print().

Your receiving code actually expects you to send '<', '1', '5', '0', '>'. Why don't you?

Some basic arduino to arduino test code. Be aware that changes in the tx/rx wiring may be needed depending on if you want serial monitor display and to avoid an endless loop condition.

//zoomkat 3-5-12 simple delimited ',' string tx/rx 
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino tx pin to the receiving arduino rx pin. 
//Connect the arduino grounds together. 
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test
//A diode between the slave tx and master rx is suggested 
//for isolation, with diode band attached to slave tx side. 
//

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

zoomkat:
Some basic arduino to arduino test code. Be aware that changes in the tx/rx wiring may be needed depending on if you want serial monitor display and to avoid an endless loop condition.

//zoomkat 3-5-12 simple delimited ',' string tx/rx 

//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino tx pin to the receiving arduino rx pin.
//Connect the arduino grounds together.
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test
//A diode between the slave tx and master rx is suggested
//for isolation, with diode band attached to slave tx side.
//

String readString;

void setup() {
 Serial.begin(9600);
 Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

//expect a string like wer,qwe rty,123 456,hyre kjhg,
 //or like hello world,who are you?,bye!,

if (Serial.available())  {
   char c = Serial.read();  //gets one byte from serial buffer
   if (c == ',') {
     if (readString.length() >0) {
       Serial.print(readString); //prints string to serial port out
       Serial.println(','); //prints delimiting ","
       //do stuff with the captured readString
       readString=""; //clears variable for new input
     }
   }  
   else {    
     readString += c; //makes the string readString
   }
 }
}




Thank for your help! 
I also get one question. When I changed the data from rotating potentiometer, data is processed through map() function and the numbers range from 0-180 as degrees. However, the serial monitor from slaver does not instantly change the received number whenever I rotate potentiometer. I can solve that after I turn off the serial monitor from slaver and turn on it again Can you give me some suggestion/
Note!
I communicate 2 arduino board (UNO and MEGA) via bluetooth modules HC-05
Mega is the master TX and RX of bluetooth connect to pin 10 and 11 respectively.
Uno is the slaver TX and RX of bluetooth connect to pin 10 and 11 respectively.

If you are using pots, and are are sending data over a wireless connection, the below code might be of interest. This is for controlling servos via pots/joystick and setup to limit the transmission of repeated data to save bandwidth. You don't need a servo to test the code, you should be able to see wht is going on using the serial monitor of each arduino.

TX code

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h> 
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(2);  
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  myservo5.attach(6);
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    Serial.print(newval1); //print the new value for testing 
    Serial.print("a,");
    oldval1=newval1; //set the current old value
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){  
    myservo2.write(newval2);
    Serial.print(newval2);
    Serial.print("b,");
    oldval2=newval2;
  }

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179); 
  if (newval1 < (oldval3-2) || newval3 > (oldval3+2)){  
    myservo3.write(newval3);
    Serial.print(newval3);
    Serial.print("c,");
    oldval3=newval3;
  }

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179); 
  if (newval4 < (oldval4-2) || newval4 > (oldval4+2)){  
    myservo1.write(newval4);
    Serial.print(newval4);
    Serial.print("d,");
    oldval4=newval4;
  }

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179); 
  if (newval5 < (oldval5-2) || newval5 > (oldval5+2)){  
    myservo5.write(newval5);
    Serial.print(newval5);
    Serial.print("e,");
    oldval5=newval5;
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}

RX code

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

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

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

This

void loop() {
 // recvOneChar();
 // showNewData();
 if(BluetoothSerial.available() > 0)
    rc = BluetoothSerial.read();
    receivedChars[ndx] = rc;
    Serial.print("This just in ... ");
   Serial.println((char*)receivedChars);
   delay(1000);
}

gives me the impression that you have made a dog's breakfast out of one of the examples in Serial Input Basics

Just use the examples as they are - then they will work!

As @PaulS has suggested use the 3rd example, for greatest reliability.

...R