Why serial monitor prints AT commands mixed and sometimes double or more

Hello, I am working with Sim808 module MK2 and using popular sketch (where are my car). Some reason serial monitor prints AT commands mixed in one line, sometimes twice or more. Later I will attach my sketch.

Thanks

https://www.cooking-hacks.com/projects/arduino-realtime-gps-gprs-vehicle-tracking

Later I will attach my sketch.

It was dumb to post the question without the code. We could have waited.

The code in the link, I am using same one

What is the point of posting a link to someone else's code? We asked for yours. And please post it here, in code tags.

My crystal ball tells be that you are using software serial to communicate with the SIM808, and you have echo on.

int8_t answer;
int onModulePin= 12;
char aux_string[30];
int flag = 0;
char number [20];
char realnumber[9];
char mynumber[9];
int a=0;
int b=0;
int c=0;
//Your phone number
char phone_number[]="07864941640";  

char data[100];
int data_size;

char aux_str[30];
char aux;
int x = 0;
char N_S,W_E;

char url[] = "http://www.mhprojects.co.uk";
char frame[200];

char latitude[15];
char longitude[15];
char altitude[6];
char date[16];
char time[7];
char satellites[3];
char speedOTG[10];
char course[10];

void setup(){
    mynumber[0]='0';
    mynumber[1]='7';
    mynumber[2]='8';
    mynumber[3]='6';
    mynumber[4]='4';
    mynumber[5]='9';
    mynumber[6]='4';
    mynumber[7]='1';
    mynumber[8]='6';
    mynumber[9]='4';
    mynumber[10]='0';
    
    
    Serial.begin(9600);
        
    pinMode(onModulePin, OUTPUT);
    
    power_on();
    power_onGPS();
    power_onSMS();
    
    delay(5000);
    
    //sendATcommand("AT+CPIN=****", "OK", 2000);  
  
    //delay(3000);  

    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 1000) || sendATcommand("AT+CREG?", "+CREG: 0,5", 1000)) == 0 );


    sendATcommand("AT+CLIP=1", "OK", 1000); 
    
    while ( start_GPS() == 0);

    while (sendATcommand("AT+CREG?", "+CREG: 0,1", 2000) == 0);

    // sets APN , user name and password
    sendATcommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK", 2000);
    sendATcommand("AT+SAPBR=3,1,\"APN\",\"giffgaff.com\"", "OK", 2000);
    sendATcommand("AT+SAPBR=3,1,\"USER\",\"giffgaff\"", "OK", 2000);
    sendATcommand("AT+SAPBR=3,1,\"PWD\",\"\"", "OK", 2000);

    // gets the GPRS bearer
    while (sendATcommand("AT+SAPBR=1,1", "OK", 20000) == 0)
    {
        delay(5000);
    }
    
    //delay(1000);
    while(Serial.available() != 0)
    {
      Serial.read();  
    }
}
void loop(){
    
    answer = sendATcommand("", "+CLIP", 1000);
    //Detect incomming call
    if (answer == 1)
    {
        Serial.println("Incoming call");          
          
          if ( flag == 0){
            
              for (int i=0; i<19; i++){
               // read the incoming byte:
               while (Serial.available() == 0)
               {                 
                 delay (50);
               }
               //Stores phone number
               number[i] = Serial.read();  
               
              }
              Serial.flush();
              flag = 1; 
          }          
          //Stores phone calling number
          for (int i=0; i<=14; i++){
            if(number[i]== '"'){
              i++;
              realnumber[0]=number[i];
              i++;
              realnumber[1]=number[i];
              i++;
              realnumber[2]=number[i];
              i++;
              realnumber[3]=number[i];
              i++;
              realnumber[4]=number[i];
              i++;
              realnumber[5]=number[i];
              i++;
              realnumber[6]=number[i];
              i++;
              realnumber[7]=number[i];
              i++;
              realnumber[8]=number[i];
              i++;
              realnumber[9]=number[i];
              i++;
              realnumber[10]=number[i];
              
              break;
            }            
    }
    //Check phone number
    for (int i=0;i<9;i++){ 
      if (realnumber[i] == mynumber[i]){
          a++;       
          if( a==9){  
             Serial.println("Correct number");
             sendATcommand("ATH", "OK", 1000);
               if(b==1){
                  b=0;
                }else{                  
                  b=1;
                  c=1;
                    }
                    break;
                  }
                }else{             
                  Serial.println("Wrong number");
                  break;
                 }
              }          
     a=0;
     answer=0;
     flag = 0;     
}
//Send SMS once and position to HTTP                   
if (b==1){
     get_GPS();
     send_HTTP();
     delay(500);                                       
    if (c==1){
      sendSMS();
      delay(100);
      c=0;                   
      }               
     }
}

void power_on(){

    uint8_t answer=0;

    digitalWrite(onModulePin,HIGH);
    delay(4000);
    digitalWrite(onModulePin,LOW);

    while(answer == 0){     // Send AT every two seconds and wait for the answer
        answer = sendATcommand("AT", "OK", 1000);    
    }
}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;


    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);
    
     while(Serial.available() > 0) Serial.read();    // Clean the input buffer
    if (ATcommand[0] != '\0')
    {
        Serial.println(ATcommand);    // Send the AT command 
       
    }


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(Serial.available() > 0){    // if there are data in the UART input buffer, reads it and checks for the asnwer
            response[x] = Serial.read();
            
            Serial.print(response[x]);
            x++;
            
            if (strstr(response, expected_answer) != NULL)    // check if the desired answer (OK) is in the response of the module
            {
                answer = 1;
            }
        }
    }
    while((answer == 0) && ((millis() - previous) < timeout));    // Waits for the asnwer with time out

    return answer;
}

void power_onGPS(){

    uint8_t answer=0;

    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(4000);
        digitalWrite(onModulePin,LOW);

        // waits for an answer from the module
        while(answer == 0){  
            // Send AT every two seconds and wait for the answer   
            answer = sendATcommand("AT", "OK", 1000);    
        }
    }

}

int8_t start_GPS(){

    unsigned long previous;

    previous = millis();
    // starts the GPS
    sendATcommand("AT+CGNSPWR=1", "OK", 2000);
    sendATcommand("AT+CGNSSEQ=RMC", "OK", 2000);

    // waits for fix GPS
    //while(( (sendATcommand("AT+CGPSSTATUS?", "2D Fix", 5000) || 
        //sendATcommand("AT+CGPSSTATUS?", "3D Fix", 5000)) == 0 ) && 
        //((millis() - previous) < 90000));

    if ((millis() - previous) < 90000)
    {
        return 1;
    }
    else
    {
        //return 0;    
    }
}

its part of code as its very long

Are you using the Serial monitor? It looks like the code you posted is trying to talk to the SIM808 using the same pins as the serial monitor does.

    mynumber[0]='0';
    mynumber[1]='7';
    mynumber[2]='8';
    mynumber[3]='6';
    mynumber[4]='4';
    mynumber[5]='9';
    mynumber[6]='4';
    mynumber[7]='1';
    mynumber[8]='6';
    mynumber[9]='4';
    mynumber[10]='0';

Writing 11 values in a 9 element array is not very bright.

              i++;
              realnumber[0]=number[i];
              i++;
              realnumber[1]=number[i];
              i++;
              realnumber[2]=number[i];
              i++;
              realnumber[3]=number[i];
              i++;
              realnumber[4]=number[i];
              i++;
              realnumber[5]=number[i];
              i++;
              realnumber[6]=number[i];
              i++;
              realnumber[7]=number[i];
              i++;
              realnumber[8]=number[i];
              i++;
              realnumber[9]=number[i];
              i++;
              realnumber[10]=number[i];

Not using a for loop to write 11 values into a 9 element array is not very bright.

its part of code as its very long

Clearly
far
longer
than
it
needs
to
be.

dannable:
Are you using the Serial monitor? It looks like the code you posted is trying to talk to the SIM808 using the same pins as the serial monitor does.

I have enabled Serial monitor, another issue code power down arduino, not Sim808. After call I get line till url and it's power down

My sim808 shield already have fixed pins, can i do like this and SoftwareSerial dedicate Serial monitor to different pins?

SoftwareSerial Serial(4, 5); // RX, TX

I have as well switch on board

  1. Function switch
  2. None­­ Vacant SIM808 serial pin to download the sketch, please dial to here.
  3. USB_DBG­­ When the expansion board plugged on the Arduino, dial to here to make SIM808 communicate with PC to make a debug (AT debugging).
  4. Arduino­­ When the expansion board plugged on the Arduino, dial to here to make SIM808 communicate with Arduino.

My sim808 shield already have fixed pins, can i do like this and SoftwareSerial dedicate Serial monitor to different pins?

If the shield has fixed pins that are to be used for serial input/output (as most do), then, no, you can't just use two other pins.

Ok, i done some mods for code, basically was my mistake with url address, I am getting sms but with weird details, have a look, if I am using code without sms function I can get all readings on serial monitor nicely, after mixed code have wrong inputs in the Gps string, any idea?

any idea?

There must be something wrong with your code. You are most likely blocking somewhere, causing data from the GPS to be lost.