Help with timer

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int motorPin = 11;
const int motorPin2 = 12;
const int motorPin3 = 13;

// defines variables

long duration;
int distance;

void setup() {

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); 
pinMode(motorPin, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);

Serial.begin(9600); // Starts the serial communication


}
void loop() {


digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance= duration*0.034/2;

Serial.print("Distance: ");
Serial.println(distance);
delay(100);



if (distance < 50)
{
digitalWrite(motorPin3, HIGH);
delay(100);  
digitalWrite(motorPin, LOW);
delay(1000);
digitalWrite(motorPin, HIGH);
digitalWrite(motorPin2, LOW);
delay(1000);
digitalWrite(motorPin2, HIGH);

}else{

digitalWrite(motorPin, LOW);
digitalWrite(motorPin3, LOW);


   
}

}
#include <TimeLib.h>
#include <TimeAlarms.h>

AlarmId id;

void setup() {
  Alarm.timerRepeat(15, Repeats);           // timer for every 15 seconds

}

void loop() {

  Alarm.delay(1000);
}

void Repeats() {
  Serial.println("15 second timer");
}

void Repeats2() {
  Serial.println("2 second timer");
}

void OnceOnly() {
  Serial.println("This timer only triggers once, stop the 2 second timer");
  // use Alarm.free() to disable a timer and recycle its memory.
  Alarm.free(id);
  // optional, but safest to "forget" the ID after memory recycled
  id = dtINVALID_ALARM_ID;
  // you can also use Alarm.disable() to turn the timer off, but keep
  // it in memory, to turn back on later with Alarm.enable().
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Hi,
Im having problems implementing a timer-function in my code. I want my dc motor to start when the sensor reaches <50, . But I also want it to have it running every 15 min. I tried to put a timer function in the code but I am not managing getting everything together. I don't know how to implement the timer function so that it would effect motorPin3, to run permanently ever 15 min for 1 sec. I know it is also a bit of a cut and past work I've done, but I am trying.

You can do this without timer library classes with code similar to that below (untested).
You maintain your own timer by holding the value of millis() when an event occurred, and test it periodically against the current value of millis().
This technique does not, however, work well if you also use delay() statements in your code, which anyway you should avoid because these block everything else.

void loop() {
   static unsigned long lastRun = 0 ;  // static initialised only at program start.
   static bool motorOn = false ;

   if ( millis() - lastRun > 15UL * 60UL * 1000UL ) {
       // every 15 minutes reset last run
       lastRun = millis() ;
       motorOn = true ;
       // start motor here
       digitalWrite(motorPin3, HIGH);
   }

   if ( millis() - lastRun > 1000UL && motorOn == true   ) {
      motorOn == false ;
      // stop motor here
      digitalWrite(motorPin3, LOW);
   }
}