# Actuate a servo once per minute

**URL:** <https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951>\
**Category:** Programming\
**Created:** [December 6, 2020, 8:22pm UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951 "2020-12-06T20:22:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinbright](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kevinbright](https://forum.arduino.cc/u/kevinbright)\
**Post date:** [December 6, 2020, 8:22pm UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951/1 "2020-12-06T20:22:13Z")

</div>

Hi,

I'm working on a mechanical clock:

[![](https://europe1.discourse-cdn.com/arduino/original/4X/d/4/4/d44fa4700b0adee67be608823d2a61f1c59004bd.jpeg "Mechanical 3D Printed "Digital" Clock") ](https://www.youtube.com/watch?v=8XKrbPzLx6M)

The clock uses one servo that has to be actuated once every minute. The design uses Geneva gears to increment the other digits automatically. For example, after the right-most digit goes to 9, the digit next to it automatically gets incremented when the right-most digit flips from 9 to 0.

I have everything working and I'm currently using the Servo example "Sweep" modified as follows:

```cpp
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 38; pos += 1) { 
    // in steps of 1 degree
    myservo.write(pos);              
    delay(100);                       
  }
  for (pos = 38; pos >= 0; pos -= 1) { 
    myservo.write(pos);              
    delay(100);                       
  }
}

```

This works as a demo, but as you can see from the video, it just increments the numbers but isn't keeping time. Basically, I need to have it sweep from 0 to 38 and back once per minute and then stop until the next minute. Everything else is automatic. Looking for tips on how best to accomplish that. I know time can be tricky when it needs to be accurate. Thanks.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [December 6, 2020, 8:27pm UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951/2 "2020-12-06T20:27:24Z")

</div>

If you need that kind of accuracy, you may have to use a Real Time Clock (RTC). Arduino millis() timing may not be accurate enough.

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [December 7, 2020, 5:21am UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951/3 "2020-12-07T05:21:12Z")

</div>

How 'bout a millis() timer? Compiles on Nano, but untested:

```cpp
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

unsigned long startTime, endTime = 60000; // 60 seconds, adjust number to calibrate

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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

void setup() {
  myservo.write(pos);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  startTime = millis();
  doSweep();
}

void loop() {
  if(millis() - startTime > endTime)
  {
    startTime += endTime;
    doSweep();
  }
}

void doSweep()
{  
  for (pos = 0; pos <= 38; pos += 1) {
    // in steps of 1 degree
    myservo.write(pos);             
    delay(100);                       
  }
  for (pos = 38; pos >= 0; pos -= 1) {
    myservo.write(pos);             
    delay(100);                       
  }
}

```

---

<div class="post-metadata">

**Author:** ![kevinbright](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kevinbright](https://forum.arduino.cc/u/kevinbright)\
**Post date:** [December 7, 2020, 9:05pm UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951/4 "2020-12-07T21:05:17Z")

</div>

Thanks... I'll test it out... seems like a good start even if it doesn't work.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:53am UTC](https://forum.arduino.cc/t/actuate-a-servo-once-per-minute/685951/5 "2021-05-06T00:53:12Z")

</div>

Closed on May 6, 2021, 12:53am UTC


