user42023: All good afternoon or evening. I am having a problem writing a sketch for Arduino using Arduino UNO and Bluetooth HC - 06.
My program does not divide the input stream of information into several variables. No matter how many variables I specify, they are considered as one. 
Maybe I do not know all subtleties of the use of Serial.read(). Apparently from a sketch given below I get through Bluetooth two variables of color and var. A microcontroller perceives these two variables as one and as a result does not execute before him task. As a result we will be able to choose the color and change delay of blinking by this color.
If anybody knows how to correct this problem or can point me to a similar project I will be very thankful for any rendered help
const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int chosed_color;
int val; 
int color;

void setup() 
{
  Serial.begin(9600);
  pinMode( rPin, OUTPUT );
  pinMode( gPin, OUTPUT );
  pinMode( bPin, OUTPUT );

}

void loop() 
{
while(Serial.available()>0)
  {
     color = Serial.read();
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );       
      digitalWrite(rPin, LOW);  
       return chosed_color;
      }
        else if(color==2)
      {
       chosed_color = bPin;
       digitalWrite( bPin, HIGH );     
      digitalWrite(bPin, LOW);  
       return chosed_color;
      }
         else if(color==3)
      {
        chosed_color = gPin;
       digitalWrite( gPin, HIGH );
       digitalWrite(gPin, LOW);  
       return chosed_color;
      }
  }
if(Serial.available()>0) 
{
  val = Serial.read();
}

      digitalWrite( rPin, HIGH );
      delay(val);       
      digitalWrite(rPin, LOW);  
      delay(val); 
}


user-1: Your code have various issues.
This:
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );       
      digitalWrite(rPin, LOW);  
       return chosed_color;
      }

means that when you find a color, you exit loop() instead of reading the val variable.
Serial.read
Serial.read read only one byte. If you need to read an arbitrary integer, need Serial.parseInt or some elaborate solution. As it, you are only able to read one-digit integer values.
Worse, when you type "1" in the Serial Monitor, what the program received is the value 49 (the ascii code for char 1).
Also, you have to filter non interesting chars, like LF, CR, commas or whatever char you use as delimitir.
Please, read the excelent post by Majenko about Reading Serial on the Arduino.
Here a better version of your code. It is very basic and lacks all error checking, etc.
const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int pins[3] = {rPin, gPin, bPin};

void setup()
{
    Serial.begin(9600);
    pinMode(rPin, OUTPUT);
    pinMode(gPin, OUTPUT);
    pinMode(bPin, OUTPUT);
}

void loop()
{
    if(Serial.available()>0) {
        int color = Serial.read();
        int chosed_color = pins[color-1];
        digitalWrite(chosed_color, HIGH);
        digitalWrite(chosed_color, LOW);

        if(Serial.available()>0) {
            int val = Serial.read();
            digitalWrite(chosed_color, HIGH); // I suppose you want this
            delay(val);
            digitalWrite(chosed_color, LOW);
            delay(val);
        }
    }
}


user42015: You have a misconception, how serial communication works. The data is transmitted one byte at a time and not in one bunch (even if you type it in the Serial Monitor in as one string). So, when you use distinct if- or while-statements for each variable, the data may arrive at any step in these statements, without any possibility to distinguish between the variables.
You have to ways dealing with serial messages (I prefer the latter for it is more flexible):

Constant message length: You can always send messages with the same length. This is suitable for small projects with only one functionality, so that you always send the same amount of data. In this case you can wait for all bytes of a message to arrive and then treat the message as a whole:

if(Serial.available() >= 2){
  variable1 = Serial.read();
  variable2 = Serial.read();
}


Using a delimiter character for each message: After each message you can send an extra byte, which value you treat as a delimiter for a message. Normally with this method you save each available byte in an extra buffer, until you receive your delimiter character (often the newline character is used '\n'):

void setup(){
  String message="";
}

void loop(){
  while(Serial.available>0){
    char c = Serial.read();
    if(c == '\n'){
      // Message is complete in buffer variable
      // Extract values from it
      if(message.length>0){
        byte variable1 = message[0];
      }
      if(message.length>2){
        int variable2 = (message[1] << 8) | message[2];
      }
      // Reset buffer variable
      message = "";
    } else {
      // Message is not complete, add byte to buffer variable
      message += c;
    }
  }
}

As said in the other answers you have to decide, how to send numerical data. 

You can send direct byte data as I used in the code above. When you are sending a bigger value to the Arduino than 1 byte, you can take the corresponding number of bytes from the buffer and put them into one variable (<< 8 shifts the byte data 8 bytes to the left (in the direction of the MSB); | makes a bytewise or, that puts the bytes together in this code).
If you want to type in values in the serial monitor, you have to consider, that these are simple ASCII encoded strings. In this case you can use the String.toInt() function and it's siblings on a substring of your message, that contains the numerical value.


42023: <p>All good afternoon or evening. I am having a problem writing a sketch for Arduino using Arduino UNO and Bluetooth HC - 06.</p>

<p>My program does not divide the input stream of information into several variables. No matter how many variables I specify, they are considered as one. </p>

<p>Maybe I do not know all subtleties of the use of Serial.read(). Apparently from a sketch given below I get through Bluetooth two variables of color and var. A microcontroller perceives these two variables as one and as a result does not execute before him task. As a result we will be able to choose the color and change delay of blinking by this color.</p>

<p>If anybody knows how to correct this problem or can point me to a similar project I will be very thankful for any rendered help</p>

<pre><code>const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int chosed_color;
int val; 
int color;

void setup() 
{
  Serial.begin(9600);
  pinMode( rPin, OUTPUT );
  pinMode( gPin, OUTPUT );
  pinMode( bPin, OUTPUT );

}

void loop() 
{
while(Serial.available()&gt;0)
  {
     color = Serial.read();
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );       
      digitalWrite(rPin, LOW);  
       return chosed_color;
      }
        else if(color==2)
      {
       chosed_color = bPin;
       digitalWrite( bPin, HIGH );     
      digitalWrite(bPin, LOW);  
       return chosed_color;
      }
         else if(color==3)
      {
        chosed_color = gPin;
       digitalWrite( gPin, HIGH );
       digitalWrite(gPin, LOW);  
       return chosed_color;
      }
  }
if(Serial.available()&gt;0) 
{
  val = Serial.read();
}

      digitalWrite( rPin, HIGH );
      delay(val);       
      digitalWrite(rPin, LOW);  
      delay(val); 
}
</code></pre>
 -1: <p>Your code have various issues.</p>

<p>This:</p>

<pre><code>   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );       
      digitalWrite(rPin, LOW);  
       return chosed_color;
      }
</code></pre>

<p>means that when you find a color, you exit <code>loop()</code> instead of reading the <code>val</code> variable.</p>

<p><strong>Serial.read</strong></p>

<p><code>Serial.read</code> read only one byte. If you need to read an arbitrary integer, need <code>Serial.parseInt</code> or some elaborate solution. As it, you are only able to read one-digit integer values.</p>

<p>Worse, when you type "1" in the Serial Monitor, what the program received is the value 49 (the ascii code for char 1).</p>

<p>Also, you have to filter non interesting chars, like LF, CR, commas or whatever char you use as delimitir.</p>

<p>Please, read the excelent post by Majenko about <a href="https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/" rel="nofollow noreferrer">Reading Serial on the Arduino</a>.</p>

<p>Here a better version of your code. It is very basic and lacks all error checking, etc.</p>

<pre><code>const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int pins[3] = {rPin, gPin, bPin};

void setup()
{
    Serial.begin(9600);
    pinMode(rPin, OUTPUT);
    pinMode(gPin, OUTPUT);
    pinMode(bPin, OUTPUT);
}

void loop()
{
    if(Serial.available()&gt;0) {
        int color = Serial.read();
        int chosed_color = pins[color-1];
        digitalWrite(chosed_color, HIGH);
        digitalWrite(chosed_color, LOW);

        if(Serial.available()&gt;0) {
            int val = Serial.read();
            digitalWrite(chosed_color, HIGH); // I suppose you want this
            delay(val);
            digitalWrite(chosed_color, LOW);
            delay(val);
        }
    }
}
</code></pre>
 42015: <p>You have a misconception, how serial communication works. The data is transmitted one byte at a time and not in one bunch (even if you type it in the Serial Monitor in as one string). So, when you use distinct if- or while-statements for each variable, the data may arrive at any step in these statements, without any possibility to distinguish between the variables.</p>

<p>You have to ways dealing with serial messages (I prefer the latter for it is more flexible):</p>

<ul>
<li><strong>Constant message length:</strong> You can always send messages with the same length. This is suitable for small projects with only one functionality, so that you always send the same amount of data. In this case you can wait for all bytes of a message to arrive and then treat the message as a whole:</li>
</ul>

<pre class="lang-cpp prettyprint-override"><code>if(Serial.available() &gt;= 2){
  variable1 = Serial.read();
  variable2 = Serial.read();
}
</code></pre>

<ul>
<li><strong>Using a delimiter character for each message:</strong> After each message you can send an extra byte, which value you treat as a delimiter for a message. Normally with this method you save each available byte in an extra buffer, until you receive your delimiter character (often the newline character is used <code>'\n'</code>):</li>
</ul>

<pre class="lang-cpp prettyprint-override"><code>void setup(){
  String message="";
}

void loop(){
  while(Serial.available&gt;0){
    char c = Serial.read();
    if(c == '\n'){
      // Message is complete in buffer variable
      // Extract values from it
      if(message.length&gt;0){
        byte variable1 = message[0];
      }
      if(message.length&gt;2){
        int variable2 = (message[1] &lt;&lt; 8) | message[2];
      }
      // Reset buffer variable
      message = "";
    } else {
      // Message is not complete, add byte to buffer variable
      message += c;
    }
  }
}
</code></pre>

<p>As said in the other answers you have to decide, how to send numerical data. </p>

<ul>
<li>You can send direct byte data as I used in the code above. When you are sending a bigger value to the Arduino than 1 byte, you can take the corresponding number of bytes from the buffer and put them into one variable (<code>&lt;&lt; 8</code> shifts the byte data 8 bytes to the left (in the direction of the MSB); <code>|</code> makes a bytewise or, that puts the bytes together in this code).</li>
<li>If you want to type in values in the serial monitor, you have to consider, that these are simple ASCII encoded strings. In this case you can use the <code>String.toInt()</code> function and it's siblings on a substring of your message, that contains the numerical value.</li>
</ul>
