ULTRASONIC SRF04 getting 0 on operation

Hello my friends couldnt find an answer on the forum about what i want,so..

I got an ultrasonic sensor,i uploaded a sample sketch so i could see if the measurements where right,then sudenly after some distance changes my ping(serial print measurement goes to 0 and stayed over there for ever.I searched it and i try to reset it somehow,i found an if statement that you just making output the echo pin ,then make it LOW and again input

if ( sonar.ping_cm() == 0 )
{

pinMode(ECHO_PIN, OUTPUT);
digitalWrite(ECHO_PIN, LOW);
delay(1);
pinMode(ECHO_PIN, INPUT);
}

It was working allright,but i keep getting zeros (0) sometimes,its reseting but i keep getting them and i dont wont that...here is why, I just made a homemade security alarm with many sensor including the ultrasonic, so i was getting random zeros and my siren cought that zeros and it was high again and again for noreason,then i searched again and i found the library NEWPING.

]Arduino Playground - HomePage

I tryed the sample sketch but i got the same problem,then i tryed the timer sketch,and it work perfectly for every insta distance check,but it was stopping the triggering,and then after a time it was starting again, i dont know how to control the time for the trigger to be high to increase the value,there is any option-feature in that library that i can send pings for ever and just ignore the zeros? im not talking about max distance, i got a standard obstickle before the max distance.
I dont want for any random reason to give me 0 when the distance is not zero.
thats all ,can you suggest me a sample of code so i can ping forever and ignore zeros? thank you very much and sorry for my english

hello Kaloudis94

I faced a similar problem during the little time I spent building a simple obstacle avoiding robot using the SRF04, I would randomly get 4 cm as the output from my sensor, I tried to alter my code but the problem didn't go away, so just like you I put an if statement in the code to ignore 4's altogether as it didn't make much difference for my particular application.

if(distance <=10 && distance != 4) // turns the robot when distance is less than equal to 10 and not equal to 4

{

//do something

}

but I believe you should try changing your sensor, my problem vanished completely once I installed a new sensor

Thank you for your reply...could you please tell me what model of ultrasonic sensor did you used after all;;