Automated Ball Roller With Arduino and One Servo

Published

Introduction: Automated Ball Roller With Arduino and One Servo

About: I am an American teaching English at Shangluo University, Shaanxi. I like making machines that do interesting but fairly useless things - I call them Quixotic Machines.

This is a simple little Arduino and servo project that takes about two hours to complete. It uses a servo to lift one end of a jar cap so as to spin a steel ball around the inside circumference. It is self starting, can change speed and can spin two (or more?) balls at once. Fun to build and get working. The timing parameters can be played with for probably even faster speeds. A few hall effect sensors with a magnetic ball could be used to make it a smarter machine that can figure out the best parameters.

I should mention that someone here at instructables.com has a more sophisticated ball roller machine: https://www.instructables.com/id/Perpetual-Ball-Ro...

Materials needed:

Arduino Uno (or any Arduino)

Servo shield (optional)

9g servo

jar cap

steel ball

some scrap wood

Step 1: Make Base and Hinged Cap Holder

The base is just a hunk of wood to mount the hinged piece of wood on. The hinged wood should be larger than a jar cap that you will use and have enough room for the hinges and to mount the servo.

I used little plastic rc aircraft hinges and just hotglued them to the hinged wood and the base.

Step 2: Make Longer Servo Arm and Attach Servo

To make a longer servo arm I just attached a 5 centimeter piece of wood to the servo arm with a couple of small screws and nuts. The servo arm should be at 90 degrees on the servo when it is horizontal to the base.

I just hot glued the servo to the hinged wood holder but I found that if you let it run for longer than a few minutes, the servo will heat up the hot glue and let go from the wood. So a better attachment method is warranted.

Step 3: Load and Run Sketch

I attached my servo to pin 7 using a shield because it is just convenient and they only cost a few bucks. If you don't have a shield then attach the servo signal wire to pin 7 on the Arduino, the red wire to 5v on the Arduino and the ground wire to GND on the Arduino. The arduino should provide enough current to operate the servo. I use the shield because it is easy to use an external voltage just for the servo.

Here is the sketch. I wrote a servo speed controller routine so as to alter the speed of the servo because it probably won't work well at full speed.

You can alter the timingDelay to get different speeds of ball rolling. You could also alter the third parameter of the myServo() function to change speed as well.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// created by Jim Demello, Shangluo University, 2017

// you are free to use, manipulate, do whatever you wish with this code, my name is not required

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include Servo.h

Servo myservo1,myservo2; // create servo object to control a servo

void myServo(int newAngle,int angleInc,int incDelay,int servoNum) {

int curAngle;

if (servoNum== 1) { curAngle = myservo1.read(); }

if (servoNum== 2) { curAngle = myservo2.read(); }

if (curAngle < newAngle) {

for(int angle=curAngle;angle < newAngle;angle += angleInc) {

if (servoNum == 1) myservo1.write(angle);

if (servoNum == 2) myservo2.write(angle);

delay(incDelay); }

}

else if (curAngle > newAngle) {

for(int angle=curAngle;angle > newAngle;angle -= angleInc) {

if (servoNum == 1) myservo1.write(angle);

if (servoNum == 2) myservo2.write(angle);

delay(incDelay); }

}

}

int timingDelay = 170; // works at 10

int noLoops = 5;

void setup()

{

Serial.begin(9600);

delay(100);

myservo1.attach(7); // attaches the servo on pin 7 to the servo object

myservo1.write(90);

delay(5000);

startUp();

}

void loop() {

spin3(200);

exit(0); //pause program - hit reset to continue

}

void startUp() {

myServo( 150,1,2,1); // neutral

delay(270);

myServo( 90,1,1,1); // neutral

delay(100);

}

void spin2() {

timingDelay = 180;

myServo( 90,1,4,1); // neutral

delay(timingDelay);

myServo( 130,1,6,1); // down

delay(timingDelay);

}

void spin3(int no) {

timingDelay = 180;

for (int i = 0;i

noLoops = noLoops - 1;

if (noLoops == 1) {

noLoops = 5;

timingDelay = timingDelay - 5;

if (timingDelay < 40) timingDelay = 20; // dont go below this speed

Serial.print(" noLoops= ");Serial.println(noLoops);Serial.print(" timingDelay= ");Serial.println(timingDelay);

}

myServo( 90,1,4,1); // neutral

delay(timingDelay);

myServo( 130,1,6,1); // down

delay(timingDelay);

}

}

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Casting Contest

      Casting Contest
    • Make it Move Contest

      Make it Move Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments