ultrasonic sensor issue

my code i am using is having problems. It looks right to me but i am missing something, because when i activate the code my ultrasonic sensor makes this funny squealing sound, and it is not detecting anything. However if i run the arduino ping sketch the sensor operates fine and i can hear the clicking or ping sound clearly so i know my sensor not broke... if you have any ideas on how to fix this issue it would be muchly appreciated XD

no ideas, not even a pointer in the right direction :~

i can hear the clicking or ping sound clearly so i know my sensor not broke

You can hear your ultrasonic sensor? That doesn't seem OK to me, none of my ultrasonic sensors are audible and that kind of defies the meaning of ultrasonic.

Also, what is on pin 12 and 13? As you have defined pin 13 as speaker, yet you never use it with tone or notone, instead you have them set to pin 12.

How do you have this wired up, what pin is your sensor on? Are you running the example ping sketch unmodified? The example runs on pin 7 but your sketch is using pin 7 for M2. Maybe you have your pin settings crossed up as with the above mentioned use of the pin for speaker? If this is the case then you are constantly sending an output to the sensor as via M2.

However, without knowing how you have this wired up, I am just making wild guesses from what I can deduce from your post.

thanks for all your help i figured it out, you right i had things all criss crossed