serial communication with bluetooth module JY-MCU HC 06

My code is designed for receiving some characters from android phone.
However, there is some problem I cant figure it out.

Code for arduino mega

#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial BT(10,11);

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

void loop()
{
byte string[20];
int insize;
while(1){
if ((insize=(BT.available()))>0)
{
Serial.print("input size = ");
Serial.println(insize);
for (int i=0; i<insize; i++) {
Serial.print(string*=char(BT.read()));*

  • Serial.println(" "); *
  • }//for*
  • } //if*
  • }//while*
    }
    such as signal,"abc"
    actual OUTPUT in serial manager
    input size = 1
    97
    input size = 2
    98
    99
    expected OUTPUT in serial manager
    input size = 3
    97
    98
    99
    I don't why the program run twice.

Now can you see why we ask you to use code tags when you post code?
Please edit your post to add the code tags.

Have a look at the examples in serial input basics. One of them will probably be suitable.

...R