servo Clock

Hi guys,

I have some code and it should in theory allow a servo to rotate 90 degrees and stop, this needs to be repeated several times, the clock uses ball bearings and the servo decide which ball bearing falls in which tube, however I can get it to work for only 2 servos, the thing is i need it to run for 5, I have included the code so if anyone can help me out that would be great, currently the remaining servos don't move or just stutter for about a minute and return to their original position.

I generally am looking for this kind of layout

s2 s1
llll llll llll
l0l llll llll
l0l llll llll
l0l l0l l0l
s3 s4 s5

ok, so its not the greatest drawing but that is generally how it will work, now the hard part

Tube 1 - hours - 1-12
Tube 2 - 5mins - 5,10,15...
Tube 3 - 1mins - 1-4

Ok so now that should make more sense as to what I'm trying to do here is the code.

Cheers

#include <Servo.h>

int second =55, minute=4, hour=0; //start the time on 00:00:00
int munit,hunit,valm=0,valh=0,ledstats,i;

Servo myservo1;  // create servo objects to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;  // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position
int pos2 = 180;

void setup()
{
  myservo1.attach(3);  // attaches the servo on pin 2 to the servo object
  myservo2.attach(5);  // attaches the servo on pin 4 to the servo object
  myservo3.attach(9);  // attaches the servo on pin 6 to the servo object
  myservo4.attach(12);  // attaches the servo on pin 8 to the servo object
  myservo5.attach(7);  // attaches the servo on pin 9 to the servo object
  myservo1.write(0);
  myservo2.write(0);
  myservo3.write(179);
  myservo4.write(0);
  myservo5.write(0);
  Serial.begin(9600);
  
}
void loop()
{
  
  //Serial.println(minute);
  //Serial.println(second);
  static unsigned long lastTick = 0;
  //if (millis() - lastTick >= 1000)
  //{
    //lastTick = millis();
    //second++;
  //}
   //move forward one minute every 60 seconds
  //if (second >= 60)
  //{
    //minute++;
    //second = 0; // reset seconds to zero
  //}
  // move forward one hour every 60 minutes
  if (minute >=60)
  {
    hour++;
    minute = 0; // reset minutes to zero
  }
  if (hour >=12)
  {
    hour = 0;
    minute = 0; // reset minutes to zero
  }
  munit = minute; //sets the variable munit and hunit for the unit digits
  hunit = hour;
 Serial.println(munit);
  //minutes units
  if(munit == 1 ){ myservo1.write(0); //starts loop
  
                   myservo3.write(179);
  delay(1000);
}

  if(munit == 5 ){myservo1.write(180);
                  myservo2.write(180);
                  myservo3.write(0);
                  myservo4.write(0);                  
  //delay(5);
}
  if(munit == 6) { myservo1.write(0);
                   myservo3.write(180);}
  
  if(munit == 10) { myservo1.write(180);
                   myservo3.write(0);}
                   
  if(munit == 11) { myservo1.write(0);
                   myservo3.write(180);}
                   
  if(munit == 15) { myservo1.write(180);}
                   myservo3.write(0);
  
  if(munit == 16) { myservo1.write(0);
                   myservo3.write(180);}
                   
  if(munit == 20) { myservo1.write(180);
                   myservo3.write(0);}
  
  if(munit == 21) { myservo1.write(0);
                   myservo3.write(180);}
  
  if(munit == 25) { myservo1.write(180);
                   myservo3.write(0);}
    
  if(munit == 26) { myservo1.write(0);
                   myservo3.write(180);}
    
  if(munit == 30) { myservo1.write(180);
                   myservo3.write(0);}
     
  if(munit == 31) { myservo1.write(0);}
                   myservo3.write(180);
     
  if(munit == 35) { myservo1.write(180);
                   myservo3.write(0);}
     
  if(munit == 36) { myservo1.write(0);
                   myservo3.write(180); }
  
  if(munit == 40) { myservo1.write(180);
                   myservo3.write(0);}
  
  if(munit == 41) { myservo1.write(0);
                   myservo3.write(180);}
      
  if(munit == 45) { myservo1.write(0);
                   myservo3.write(180);}
       
  if(munit == 46) { myservo1.write(180);
                   myservo3.write(0);}
       
  if(munit == 50) { myservo1.write(0);
                   myservo3.write(180);}
       
  if(munit == 51) { myservo1.write(180);
                   myservo3.write(0);}
  
  if(munit == 55) { myservo1.write(0);
                   myservo3.write(180);}
        
         
  if(hunit == 1) { myservo1.write(180); //acknowledges an hour has passed
                   myservo2.write(180);
                   myservo3.write(0);
                   myservo4.write(0);
                   myservo5.write(180);}
        
  if(hunit == 12) { myservo1.write(180);       //acknowledges that 12 hours have passed
                    myservo2.write(180);       //releases all the ball bearings
                    myservo3.write(180);
                    myservo4.write(180);
                    myservo5.write(180);}
                    
  delay (1000);
  minute++;
  }

How are you powering the servos?
From a separate supply with common grounds, I hope.

Hi,
Further to the post above, read the two links in my signature for a video of what's most likely happening and a way to address it.

Duane B

rcarduino.blogspot.com

Hi, thanks for you input.

I have done as you advised in your post but for some reason I can't get the breadboard to hold the voltage, it seems that running 3 servos off a modified 9v power supply to produce 18v isn't enough.

As advised I need to run 5 servos off this and when running a volt meter on the breadboard it was only producing 1.8v can you advise why this may be the problem.

cheers

Get a four AA cell holder with four AA cells.
Connect the black wire to your Arduino's ground, and the red wire to the servo supply wires.
Do not use 9V batteries, unless you're powering a smoke alarm.
Do not use two 9V batteries unless you're powering two smoke alarms.

Hi,
If you are referring to my post I am concerned that you read some part of it as recommending 18volts into a servo. Please don't do this, it's three times more voltage than you should be applying, can you also point me to the part of my post that lead you to this thought, I will change it so that others do not read it the same way in future.

Thanks

Duane B

rcarduino.blogspot.com

Many servos can pull more than an amp for brief periods as they activate - if you have several servos you must have a supply that can produce several amps or the servos will simply wimp-out. Small 9V batteries cannot do this. You cannot substitute volts for amps. 4 x NiMH AA cells will do the job.

I am concerned that you read some part of it as recommending 18volts into a servo.

I assumed the 18volts were being fed to the Arduino's regulator to warm up the environment.
Either way OP, don't do it.

Hi guys thanks for the info!

Duane I didn't get that impression it was kind of a solution proposed to me by a mentor.

Needless to say that two didn't work the solution came after working out that the servos require constant voltage to run the program I've created, the 18v were diffused by the servos and so they didn't have enough power to run them hence the twitching.

After reading on the arduino site you can put up to 12v on the board and it will run!

With this in mind I have sourced a 12v transformer that gives out a constant 1amp current (off net gear router)

This allows the current to be constant and the servos don't drain the power for all other components, I am now running 6 servos 3 LEDs and a motor all off one ad board and it's been on constant now for about 5 hours so we'll see if it burns out the board.

Anyway just thought I'd share my findings with you guys

Thanks for all your help!