Do until stop or timer runs out

Hi. I have a continuous rotation servo for a bluetooth car's steering mechanism. The front wheels are connected by a beam and is controlled by a rack and pinion. The continuous rotation servo will rotate the pinion which will move the rack in a linear motion to move the beam and therefore rotate the front wheels to turn.

Now here's my problem, the user control uses a button to control the servo (Left and Right button).
In my app's program, once you let go of the button it will give a let go data.

Button left press down==send left
Button right press down==send right
Button left release==send center
Button right release==send center

I did this becuase I used a 180 degree servo motor first but now I realized that it does not give enough rotation to turn the wheels enough. Continuous rotation servo only has speed no rotation, so 90 means stop, 180 means full speed left, 0 means full speed right. What my plan is something like this:

(Not actual code just a demo plan)
Start timer

If(center||timer runs out){

The timer is there so that in case the user does not let go of the button, the servo will not run continuously and break my very good steering mechanism. So basically once the user tells the servo to center it will center, if the user does not it will stop at the maximum turning limit.

Also "delay" function is NOT an option because there will be programs that needs to be running full time. Thank you very much!:grinning::grinning::grinning:

That’s not a good starting point…
You should have a method to override/cancel the steering input if it reaches the limits!

Good luck getting the servo to centre consistently unless you have a sensor for that position too

Have you considered using a normal servo with a range of movement greater than 180 degrees, such as a sail winch servo, or gearing up the 180 servo output to increase it rotation

Well I could tweek the code for the app like:

If(clicked >1 second){
Send center
While (centering)
Block data data inputs from left and right buttons

Time will be my basis for accuracy.

Gearing the servo could be an option, however the servo is located under the car and the car is low. So gearing it would give a chance of the gears hitting the ground.

Don't expect the centering to be very accurate based on time. For one thing the speed of the servo will depend on supply voltage and the servo motor may well run at slightly different speeds in each direction

I'v seen diy rc cars that use dc motors to steer. So lets say that centering won't happen automatically. It will all depend on your left and right button. All I need for now is to stop the servo at a certain limit. I was thinking about the end of the rack, maybe the solution will be there. Any suggestion? Thanks

A limit switch at each extreme of the travel would stop the steering overrunning. Making the left and right buttons either nudge the steering in the appropriate direction or to cause the servo to run towards that direction if held down would be better than relying on automatic centering

So a limit switch at the end of the rack so when the pinion hits it, it would not turn anymor.


Is this what you are trying to say?

I am wary of commenting on what you posted because there is no context. When the steering reaches either extreme, detected by either limit switch becoming open or closed, then you need to stop the servo rotating which your "code" does not take into account

It's not really a code its just like a demonstration of what's in my mind because it might not be understandable and informal if I said it without my "sample code". But yes I will include when the servo will stop.