Using input from a Ultransonic sensor and a RTC 1302 to trigger relay

so still trying to figure this out one step at a time, Ultasonic is easy. High at one distance low at the other. Now adding a a RTC 1302 to trigger the relay every third day for 2 minutes. Have the code for relay working and finally got the RTC keeping time and reporting running time on screen. Need to set alarm trigger for 72 hours ish. And then combine all code.

Thoughts?

Maybe something like this (untested):

byte dayCounter = 0 ;
unsigned long alarmOnAtMs = 0 ;
bool alarmOn = false;


void loop() {
   if ( hour == 12 && minute == 30 && daycounter == 0 && alarmOn == false ) {   // get hour and minute from RTC (somehow)
       alarmOn = true ;
       alarmOnAtMs = millis() ;
       dayCounter ++ ;
       if ( dayCounter >= 3 )  dayCounter = 0 ;
   }

   if ( alarmOn == true && millis() - alarmOnAtMs > 120000 ) alarmOn = false ;  // 120000 = 2 minutes

   // do stuff here if alarmOn is true . . . 
}

72 hours ish

Then why use an rtc? Just use millis().

Well I used "ish"as a way to express every third or fourth day. Would like to be able to change it with out having to do a lot of conversions. Just change it from an LCD screen on the board case. At hotter times of the year and a colder times of the year or any other time a change is warranted. I am very new to any types of coding so this has been a struggle to get this far, simply because I want to understand what I am doing as apposed to just copy and paste someone else code. I am looking for ideas on how it is done and how I can put them in my project. Thanks to anyone who helps to any degree. I am still trying to figure out the RTC as even though it is still running I have no idea why it is doing the things it is doing, lol. Thanks again

ErikLehnsherr:
I am still trying to figure out the RTC as even though it is still running I have no idea why it is doing the things it is doing

What is it doing? You make it sound like it is doing something you did not expect.

My apologies for the late response...No it is running and keeping good time and date. When I say I am still trying to figure out what it is doing, I'll try to explain. As Arduino is my first venture into any type of programming I copied the RTC program code and got it running. Trying to figure out why is a different story. Most of the codes I have fooled around with I have been able to dissect and understand why they are working. RTC code was a big jump for me and has been difficult to understand what is going on. I have been researching books to help me with understanding the coding a little better, there are just so many I don't know where to begin. Just a slow process for me is all. Especially for a silly project that I could do with simple mechanical float sensors and a digital light timer, but what would the fun in that be, as well as I wouldn't learn anything new, there by wasting a day in my finite life.

Ah, ok.

Post some code snippets and your questions. Perhaps we can help you understand what is going on.