Starting a new Servo project


I am beginning a new servo project and before I dive into programing with a blank slate I would like to describe what I am trying to achieve and see if anyone can point me in the right direction to avoid wasted time/pitfalls.

This is my second arduino project and my first with a servo.

My goal is to create a device that will push a ball down a shoot every 8 hours continuously for a week. I plan to use a continuous servo to push the ball. The servo needs to make one full rotation to push the ball correctly. I already have the servo mounted in the armature and now I need to create the script.

Can anyone point me to some resources or examples to help me get my coding started?

Thanks in advance for any help!

A continuous servo has no ability to go to a precise position. Their positional feedback has been disabled. You may be able to use timing to get to a position, but any change of load, supply voltage or other parameters will change the timing. If you need more than 180° rotation and precise positioning, I recommend a geared motor with an encoder.

OK I would reconsider that choice. A continuous rotating servo will not allow you to control its position only its speed. However, this speed control is not fine enough to be set to one rotation per 8 hours . I can't see it working.

It sounds more like a project that needs a stepping motor to me.

What kind of time accuracy do you need? The Arduino internal clock is likely to be off by 5 to 10 seconds a day. If you need more accuracy than that I recommend a DS3231 Real-time Clock.

If you want to use a 'continuous rotation' servo to do a single revolution on command, you will need some kind of position feedback like a disk with a flag or hole and an IR sensor or a cam and switch. It will take some tuning to get the 'continuous rotation' servo to come to a stop. An actual servo would be the better solution.

...interesting. What is the simplest way to add a stepper to a uno that involves the fewest # of components.

also, I was planning to have the servo (or stepper motor) rotate once every 8 hours at a relatively fast speed...the rotation does not have to be drug out over 8 hours. It can rotate (over a 2 or 3 second duration) and then sit still for 8 hours.

Thanks for the feedback!

What kind of time accuracy do you need? The Arduino internal clock is likely to be off by 5 to 10 seconds a day.

That is fine. If it drifts by 10 seconds each day no big deal.

An actual servo would be the better solution.

Understood, but the way the mechanism works the servo is not able to run in reverse - to reset before it pushes out the next ball.

Can you show or describe your mechanism?

The wooden stick attached to the servo rotates and knocks the ball out of the hole. Another ball drops down to where the first one was so the wooden stick would hit the new ball if it tried to go backwards.

One possible mechanism: Put a ramp in the bottom so the ball will tend to roll out of the hole by itself. Have a servo driving two rods: A rod to block the bottom ball from rolling out and a rod above the bottom ball to keep the second ball from becoming the bottom ball. In the HOLD position the bottom ball is blocked and second ball is unblocked. In the DROP position the second ball is blocked and the bottom ball is free to roll out.

When it is time to drop a ball, move the servo to the DROP position. The second ball is blocked and the bottom ball is released. After a brief time, return to the HOLD position where the second ball is released and the bottom position is blocked to make the second ball the new bottom ball.

I would like to try this with the continuous servo as I originally envisioned it to see what the outcome is.

The Arduino IDE has some built in servo examples. File>Examples>...

Otherwise, google "arduino servo control" for tutorials, but ignore the ones that suggest to use the Arduino 5V output to power the servo.

Cheap hobby servos are intended for short term use in toys, and will not last long when put into continuous operation, 24/7.

I got the servo running and, like everyone guessed, it is hard to make the continuous servo do a full 360 rotation and then come to a stop. The wooden arm always comes to rest after its rotation in a slightly different location.

Video of mechanism in operation

#include <Servo.h>
Servo myservo;

void setup() {

void loop() {

I am thinking that the best to get the wooden arm to come to a rest at the same location each time is to have a micro switch (or some other kind of sensor) "trip" when the wooden arm passes the 6-oclock position.

In my code the "delay(3080)" would be replaced by in input from this sensor which would trigger the "detach" function to happen.

Does this sound like a good direction?

Can anyone point me in the right direction for incorporating a micro switch (or other sensor)?


Well I wouldn’t recommend it, because it depends on the velocity the arm bangs into the micro switch. The Arm has momentum which will keep it moving once you have told it to stop.

You could go past the microswitch a bit (may well do so anyway) and then reverse back until you trigger it again. How accurate does it need to be?

How accurate does it need to be?

...not very.

If I could get it to come to rest at the 6-oclock +/- 45 degrees I would be happy. The exact resting position is less important, what is most important is that the arm sweeps out a ball every cycle with 100% reliability.

The problem now is that the the act of pushing the ball out and the resistance associated with that makes the arm come to rest at very different positions...and those inaccuracies are compounded over the multiple where, on certain cycles, a ball will not be pushed out.


So do your rotation and then go find the microswitch at low speed. You can find components that are optically triggered with a slot that blocks the light that your rod could pass through.

I watched the video several times. Your project is crying for a microswitch to tell your Arduino to cut the power to the servo. Since timing is not critical, positioning is also not critical. Just the motor rotation to push the ball out. So a switch anywhere in the path after the ball is pushed will work.

I have never used a switch before in a project. Can you give me insight into how the programing might work? Looking at my original code would you agree that I would want the switch to initiate the "detach" function? How would that work with a micro switch?


The usual microswitch has three connections. "C" for common. "NO" for normally open-not connected to common. And, "NC" for normally closed, or normally connected to the common terminal.
Connect the "NO" connection to the Arduino ground. Connect the "C" to an unused Arduino pin. In your program, set that pin to input pullup, so it is always held at a high value.
Whenever the microswitch is activated, the Arduino pin will read "low" and you will know the switch as been pressed and you can "detach". Read the pin as often in your loop() as possible.

Maybe that tells you that the project you are attempting is too advanced for your current state of knowledge. The switch is the second thing you should look at after the LED. Go through a few examples in the IDE to get a feel of how to use them.