title: Sending string from pc to arduino
body: <p>I have a string, specifically, a cellphone number with 11 digits inputted from a serial port(pc) and am planning to send it to arduino. I've got no problems in inputting the string  and print it to serial buffer, what I am confused about is, is arduino really correctly read the cellphone number that I've just inputted? In addition, let's assume that arduino have already read the string, how am I going to properly insert the string in my arduino code and process everything so that it can now send SMS? I was able to send SMS using the GSMSMS code alone. I was able to do it by manually inputting a specific cellphone number. But with the 1st arduino code below, I've got errors. Did i missed something? I badly need some suggestions and hints. Thanks in advance! :)))
  Here is my arduino codes:</p>
  
  <pre><code>  char text[11];
    int  bufferIndex = 0;
    char Rx_data[50];
    unsigned char Rx_index = 0;
    int i = 0;
    char msg[160];
    int sig;
  
  
    void setup(){
    Serial.begin(38400);
        initGSM();
         loop_Serial();
        send_msg(text, "Your sample has been tested. You may now get your result. Thank you.");
    }
  
    void loop_Serial()
    {
        if( Serial.available())
      {
  char ch = (char)Serial.read();
  if( ch == '\n')  // is this the terminating carriage return
  {
    text[ bufferIndex ] = 0; // terminate the string with a 0      
    bufferIndex = 0;  // reset the index ready for another string
    // do something with the string
    Serial.println(text);
  }
  else
    text[ bufferIndex++ ] = ch; // add the character into the buffer
      }
       } 
  
    void loop() {
      //none
    }
  
    void send_msg(char *number, char *msg)
    {
      char at_cmgs_cmd[30] = {'\0'};
      char msg1[160] = {'\0'};
      char ctl_z = 0x1A;
  
      sprintf(msg1, "%s%c", msg, ctl_z);
      sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
  
      sendGSM(at_cmgs_cmd);
      delay(100);
      delay(100);
      delay(100);
      sendGSM(msg1);
      delay(100);
    }
  
    void sendGSM(char *string){
      Serial.write(string);
      delay(90);
    }
  
    void clearString(char *strArray) {
      int j;
      for (j = 100; j &gt; 0; j--)
        strArray[j] = 0x00;
    }
  
    void send_cmd(char *at_cmd, char clr){
      char *stat = '\0';
      while(!stat){
        sendGSM(at_cmd);
        delay(90);
        readSerialString(Rx_data);
  
        stat = strstr(Rx_data, "OK");
      }
      if (clr){
        clearString(Rx_data);
        delay(200);
        stat = '\0';
      }
    }
  
    void initGSM(){
  
      send_cmd("AT\r\n",1);                       
    //  send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module  
  
      send_cmd("AT+CMGF=1\r\n",1);            // Set message format to text mode
      //Sucess
  
      Serial.println("Success");
  
      delay(1000);
      delay(1000);
      delay(1000);
    }
  
    void readSerialString (char *strArray) {
  
      if(!Serial.available()) {
        return;
      }
  
      while(Serial.available()) {
        strArray[i] = Serial.read();
        i++;
      }
    }
  </code></pre>
  
  <p>AT</p>
  
  <p>AT+CMGF=1</p>
  
  <p>Success</p>
  
  <p>AT+CMGS="S"</p>
  
  <p>Your sample has been tested. You may now get your result. Thank you.</p>
  
  <p>Where "S" came from? And where's my inputted string? </p>