3001HB servo motor - simple movement every x minutes

I have the above servo motor and I would like to create a simple motion:
a long wooden stick that is connected to that motor and every 15 minutes it will plunk a metal object that is hanging from the wall.

I have never used servo motors before and I wonder how can I do the mention above?

so the servo will need to move 180 degree back and forth one time every that time period (15 minutes)

Thanks for any advice!

When You have a link to the servo datasheet it would be interesting to see it here.
For operating a servo take a look at the IDE example code for servo.

here is the datasheet
I guess those motors have limitation for the time they can go from one position to another? is this written somewhere?

Assuming I want to make a movement from resting position (0) to a position 180 degrees away then back to 0. how can I know the fastest time this can happen?

The motor's datasheet should tell you, a typical speed might be 0.12 seconds per 60 degrees, so 180 degrees would take 0.36 seconds or 360 milliseconds

https://www.pololu.com/file/0J728/HD-3001HB.pdf

How is this code for the mission?

#include <Servo.h>

Servo servo1;

const unsigned long interval = 15UL * 60 * 1000;  // 15 minutes between plunks
const unsigned long plunkDuration = 150;     // Wait time for servo to reach position

unsigned long lastPlunkEndTime = 0;
unsigned long plunkStartTime = 0;

enum State { WAITING, PLUNKING_FORWARD };
State state = WAITING;

void setup() {
  servo1.attach(9);
  servo1.write(90); // Neutral position
}

void loop() {
  unsigned long now = millis();

  switch (state) {
    case WAITING:
      if (now - lastPlunkEndTime >= interval) {
        servo1.write(60);         // Plunk forward
        plunkStartTime = now;
        state = PLUNKING_FORWARD;
      }
      break;

    case PLUNKING_FORWARD:
      if (now - plunkStartTime >= plunkDuration) {
        servo1.write(90);         // Return to neutral
        lastPlunkEndTime = now;
        state = WAITING;
      }
      break;
  }
}

It will depend on the voltage and load. It will be slower if it needs to move something heavy

Did you try it? It doesn't compile because "'plunkDuration' was not declared in this scope"
And after adding that it sweeps about 45 deg, not your required 180.

More generally: what is the length and weight of your 'stick'? And will it be parallel to the ground, so subject to a constant gravitational force during its rotation? I think the mechanics here are more challenging than the code.

BTW, your sketch seems rather over complicated for a simple sweep. Is it your own? Try adapting the built in example 'Sweep'.

It was made using ChatGPT.

I will look into that example asap!

So I try the sweep code in the example. it written that is should turn 180 degrees but it seems my motor doing only 90 degrees. I’m using for the example simple MG995 servo motor and I’m power it directly from the arduino 5V pin

ok this code seems to work just fine!

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int pos = 0;  // variable to store the servo position
float pauseMinutes = 1;      // <<<<<< CHANGE THIS VALUE (e.g., 0.5, 1, 2, 5)
unsigned long pauseDuration = pauseMinutes * 60 * 1000;  // Converted to milliseconds

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

void loop()
{
    // Sweep from 0 to 180 degrees
    for (pos = 0; pos <= 180; pos += 1)
    {
        myservo.write(pos);  // tell servo to go to position in variable 'pos'
        delay(5);           // waits 5 ms for the servo to reach the position
    }

    delay(50);  

    // Sweep from 180 to 0 degrees
    for (pos = 180; pos >= 0; pos -= 1)
    {
        myservo.write(pos);
        delay(5);
    }

    delay(pauseDuration);  // wait for x minutes
}

I wonder if there is minimum delay between servo pos that I should not exceed?

Regarding the speed of the rotation - I wonder if something in my code limit my servo from turning in full speed from 0 to 180 and back to 0.

It feels a little slow.. I wonder if it is because of my code or something else?

I am using Arduino Uno clone and I’m powering the Arduino via the barrel jack with 12V. Sevo is getting his power from the Arduino 5V pin

#include <Servo.h>

Servo myservo;

int pos = 0;

float pauseMinutes = 0.5;      // <<<<<< Change this value ( 0.5 for 30 seconds, 5 for 5 Minutes etc)
unsigned long pauseDuration = pauseMinutes * 60 * 1000;

int speedRotation = 1;  // delay between servo steps in ms

// New variable to control the pause time before returning to 0 degrees
int waitBeforeReturn = 1000; // 1000 ms = 1 second (you can change this value)

void setup() {
  myservo.attach(3);
}

void loop() {
  unsigned long sweepStart = millis();

  // Sweep from 0 to 180 degrees
  for (pos = 0; pos <= 160; pos += 1) {
    myservo.write(pos);
    delay(speedRotation);
  }

  // Wait for a configurable amount of time before going back to 0 degrees
  delay(waitBeforeReturn);  // waitBeforeReturn is in milliseconds (e.g., 1000ms = 1 second)

  // Sweep back from 180 to 0 degrees
  for (pos = 160; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(speedRotation);
  }

  unsigned long sweepEnd = millis();
  unsigned long sweepTime = sweepEnd - sweepStart;

  // Calculate remaining pause time after subtracting sweep time
  if (pauseDuration > sweepTime) {
    delay(pauseDuration - sweepTime);
  }
  // else sweep took longer than pauseDuration, so skip pause
}