Back to engineering archive

Record 019 / Firmware and control

RTC timed motor and servo controller

A DS1302 clock supplies time for two servo outputs, alongside a separate elapsed-time sequence for a linear actuator.

Firmware development
RTCMotor controlServo controlDS1302Three-wire interface
Project design or interface view — RTC timed motor and servo controller
Project design or interface view — RTC timed motor and servo controller

Firmware flow

Run an elapsed-time motor sequence

Selected motor fragment from a clock-and-servo firmware variant.

When the interval has elapsed, the firmware drives the motor for a blocking duration, stops it, advances a software position count and chooses the next direction from the count bounds.

This is elapsed-time, open-loop motion logic. The position count and comments are not measured travel, calibrated positioning or evidence of tested actuator operation.

Read the implementation

Selected firmware excerpt. The diagram explains the code; it is not a hardware test.

Selected source excerpt

  // Linear actuator logic
  if (currentMillis - lastMoveTime >= MOVE_INTERVAL) {
    lastMoveTime = currentMillis;

    moveMotor(direction);
    delay(MOVE_TIME);
    stopMotor();

    position += direction;

    if (position >= 15) {
      direction = -1;
    } else if (position <= 0) {
      direction = 1;
    }
  }
ResultContinue without a new movement
ActionSave start time and drive in the current direction
ActionWait for the configured drive duration
ActionStop the motor and update the software position
ActionSelect extend direction
ResultReturn to the main loop

Technical notes

Clock and servo outputs

The selected variant reads the DS1302 through a three-wire interface and derives servo commands from the hour and minute. Serial is used for diagnostic output.

Timed actuator movement

A separate millis()-based interval starts the motor, waits for the configured drive duration and stops it. The firmware updates a software position count and reverses direction at its count limits.

Open-loop estimates

The actuator position is estimated from timed commands, with no measured position or end-stop feedback in this source. Blocking delays and integer mapping also limit the implementation; calibrated travel and clock-display accuracy are not established.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project