Re: Help with programing. ):

Use “code”, not “color”
Any clues as to what thsi:data = MTC(duration); does?

but the servo is starting stoping and starting and so on

Sadly, the speed of sound is finite.

data = MTC(duration);

look to the bottom of the code and it tells you what that comand is.

but the servo is starting stoping and starting and so on

 delay(40);

And the PPM update rate is..?

The delay is suppost to be there I'm talking about 3 second stops twitching and then carrying on.

The servo is moving the sensor so it can scan how close objects are that is what the "delay(40);" is for.

I'm talking about 3 second stops twitching and then carrying

OK, so this is news. How are you powering the servo - not from the Arduino, I assume.

that is what the "delay(40);" is for.

R/C servos update 50 times a second.

The servo has a good power source, the delay is to slow the servo because what I am planing to do is have a nerf gun on top of the servo that will fire when an object is too close to the ping sensor.

the delay is to slow the servo

Good to know you've got a plan.

Tell us all about it. All of it, not just dripping it out as and when asked

I have tryed changing the delay... no result. The second servo (servo2) will push down on the triger of the nerf gun on top of servo1. The ping sensor is ontop of servo1 pointing the direction of the nerf gun. When the sensor output indicates that something is in a range of 60cm using sonar it fires the nerf dart it that dirction and continues scaning the area.

How much code is replicated in your loops? Clearly, since you have MTC(), you know what functions are, and have at least a vague idea how to use them.

It isn't clear to me what the issue is. You have a period of time that the sensor takes to set up to send a pulse, to send a pulse, and to get a response. The farther away an object is, the longer it takes to get a response. Then, you add a further delay after the servo is directed to move. The purpose of that delay, short as it is, escapes me.

After you make a function to operate the ping sensor, try commenting the call to the function out, and see if the servo moves smoothly. Then add the function calls back in. Any additional delay then is directly attributable to the ping sensor.

Since you want to fire a nerf gun if an object is within range, you don't need to wait the full time for pulseIn to return.

There are a number of threads that describe how to limit how long pulseIn waits for a change. You might want to determine how long it takes to sense an object that is just in range, and limit pulseIn to no longer than that time.

Hey, the reson that the delay is there is that the servo needs the time to adjust to the changes, I have changed the code so the servo.write(h); command is before the delay.

BTW I'm not an expert in the programing but I know most of the functions as I do not get taught lessons I am just learning off the internet.