RGB LED + ANDROID

Hi i'm trying to make a RGB controler via bluetooth i am using an old HC-05 module, and an android interace made in basic4android IDE.

in the interface i have 3 Seekbar in order to control the 3 pwm for the RGB led.

i wont post all my android code due the extencion of this, but if someone want it just ask it.

the data send part basicly sends 3 parts like

Tx.WriteLine("#"& SeekBar1.Value &"R" ) so thats only for one seekbar it sends delimitation characters in order to know what value its for.

this is for Green seekbar
Tx.WriteLine("#"& SeekBar1.Value &"G" )

and Blue seekbar
Tx.WriteLine("#"& SeekBar1.Value &"B" )

belong this i have my arduino code but it just not working as i espected.

i hope you can find my error and help me i think maybe its something i'm not seeing but who knows. BTW i'm mexican so i apologize for my english i know its not good enough at least as i wanted to be.

/*----------------------------------------------------- 
CONTROL DE GIRO DE MOTORES PARA SHIELD COMPATIBLE CON ARDUINO Y PINGUINO GENTOO


-----------------------------------------------------*/
byte DATO_RECIBIDO;
int LED_ROJO =0;
int LED_VERDE =0;
int LED_AZUL=0;
int x=0;
int inicio;
int fin;
int convercion;
char caracter [6]={0,0,0,0,0,0};
//rutinas


void setup() {
    // put your setup code here, to run once:
    /*pinMode(9,OUTPUT);
    pinMode(10,OUTPUT); // DECLARA LA SALIDA DEL MOTOR DER COMO SALIDA 
    pinMode(11,OUTPUT); // DECLARA MOTOR IZQUIERDO COMO SALIDA 
    pinMode(12,OUTPUT); 
    pinMode(13,OUTPUT); 
    

     */
     
     Serial.begin(9600);     // abilita el puerto serial y define la velocidad del puerto serie o BAUDRATE DEL UART
    }

void loop() {
    // put your main code here, to run repeatedly:

        if (Serial.available())// el micro pregunta si se ha recivido algun dato
        {
        caracter[x] = Serial.read(); //OBTIENE EL DATO Y LO GUARDA IMPORTANTE!
        }
        
         if (caracter[x]=='#')  //pregunta si ya llego el primer dato
         {
          inicio=1;
         }
         
        
           if (inicio==1) 
         {
          x=x+1;
         }
        
         if (caracter[x]=='R'||caracter[x]=='G'||caracter[x]=='B')//pregunta si ya llego el ultimo dato
         {
         fin=x-1;
         inicio=0;
         x=0;
         }
         
         
     
      
         
     if (fin==1){
     convercion=(caracter [1]-48);}
     if (fin==2){
     convercion=(caracter[1]-48)*10+(caracter[2]-48);}
     if (fin==3){
     convercion=(caracter[1]-48)*100+(caracter[2]-48)*10+(caracter[3]-48);}
     if (fin==4){
     convercion=(caracter[1]-48)*1000+(caracter[2]-48)*100+(caracter[3]-48)*10+(caracter[4]-48);}
   
  if(caracter[fin+1]=='R'){
  LED_ROJO=convercion;
  analogWrite(9,LED_ROJO);
}
  
  if(caracter[fin+1]=='G'){
  LED_VERDE=convercion;
     analogWrite(10,LED_VERDE);
 }
 

   if(caracter[fin+1]=='B'){
  LED_AZUL=convercion;
   analogWrite(11,LED_AZUL);
 }
    /*pinMode(9,OUTPUT);
    pinMode(10,OUTPUT); // DECLARA LA SALIDA DEL MOTOR DER COMO SALIDA 
    pinMode(11,OUTPUT); // DECLARA MOTOR IZQUIERDO COMO SALIDA 
    pinMode(12,OUTPUT); 
    pinMode(13,OUTPUT); 
    

     */

So, the pins are all INPUT. Got it.

Tx.WriteLine("#"& SeekBar1.Value &"R" )

What does the Value property contain? I'd expect that it would be an int, and that you'd have to convert that to a string. There is no sense trying to write code to handle the input, on the Arduino, until you know what the input is.

Once you are sending a string, not a mix of letters and binary data, there is no reason to store the start character in the array. So, don't. When the terminating character arrives, store it elsewhere, and add a NULL to the array, instead. Then, you'll have a NULL terminated array of chars, which is what atoi() wants.

convercion = atoi(caracter);

is far simpler that what you are currently doing.