GSM GPRS sim900 shield doesn't work properly afte turning it on

Sometimes it lasts more than 20 times that's why I don't feel safe doing that.
I somehow fixed it with millis by doing this:

 unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval){
    previousMillis = currentMillis;
    if(state == LOW){
      state = HIGH;
    }else{
      state = LOW;
    }
    digitalWrite(trigPin, state);
  }

Now for some reason all i get printed is correct distance and 0s. And i made a condition to ignore 0s. Now it works somehow.