Rain Tipping Bucket rerun weekly

Hi, im new and need some guidances. i have a rain tipping bucket and run ok. but my professor want it to run weekly. so it likes, every week the value of the count (REEDCOUNT) return to 0 and run again until end of week and so on.

im using Arduino MEGA and RTC DS3231 the programm count how much water in the tipping bucket drop. my question is, can i count the water drop in the tipping bucket weekly. for example 1st week it count til "x count", and the 2nd week the count reset to 0 and count again, and the 3rd week back again to 0 and recounting.

here is my code

/****************************
 * Global Variables         *
****************************/
#include 
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

int REED = 9; //The reed switch outputs to digital pin 9
int val = 0; //Current value of reed switch
int old_val = 0; //Old value of reed switch
int REEDCOUNT = 0; //This is the variable that hold the count of switching
float X; float Menge_des_Niederschlags; float regen = 0;


/****************************
 * Setup                    *
*****************************/
void setup(){

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(9600);
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
    }

    if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
  
  pinMode (REED, INPUT_PULLUP); //This activates the internal pull up resistor
}
/****************************
 * Main Loop                *
****************************/
void loop(){
  DateTime now = rtc.now();
  val = digitalRead(REED);
  if ((val == LOW) && (old_val == HIGH)){
    delay(10);
    REEDCOUNT = REEDCOUNT + 1;
    old_val = val;
    X = 0.1;
    Menge_des_Niederschlags = REEDCOUNT*X; //depth of rain

    Serial.print("Count = ");
    Serial.println(REEDCOUNT); //Output the count to the serial monitor Serial.print("rain = ");
    Serial.print("Menge_des_Niederschlags = ");
    Serial.print(Menge_des_Niederschlags); //Output of depth_of_rain Serial.println(" mm ");
    Serial.print(" l/m² , ");
    Serial.print(" (");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(") ");
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(10);
  }
  else {
  old_val = val; //If the status hasn't changed then do nothing
  }
}

thanks in advance

What is the question? What does the code do?

the programm count how much water in the tipping bucket drop. my question is, can i count the water drop in the tipping bucket weekly. for example 1st week it count til "x count", and the 2nd week the count reset to 0 and count again

sorry.. i had edit my post for more information

Hi Ossens, welcome to the forum! First post and you properly used code tags! Karma++

Please do try to better explain your goal.

You started with a working sketch that does some 'original task'. You modified it to meet new requirements. You expected your new sketch to so 'something'. Instead your new sketch did 'something else'.

Please explain to us what the 'original task' was. And what your expected 'something' is. And what the actual 'something else' is.

Edit: Ah, you got in some clarification just before my post. :)

One week is 7 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds (7*24*60*60*1000=604800000UL). When your code starts (in setup), you store the value of "millis()" to a variable (of type unsigned long), lets call it "week_begin_millis". For each loop you subtract "week_begin_millis" from the current value of "millis()" and if the result exceeds the amount of milliseconds in a week, then a week has passed and you set REEDCOUNT to zero and "week_begin_millis" to the value of "millis()" to begin a new week. Another method would be to set REEDCOUNT to zero at a fixed time each week (eg. Sunday at noon), using the RTC value already stored in "now".

Danois90: One week is 7 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds (7*24*60*60*1000=604800000UL). When your code starts (in setup), you store the value of "millis()" to a variable (of type unsigned long), lets call it "week_begin_millis". For each loop you subtract "week_begin_millis" from the current value of "millis()" and if the result exceeds the amount of milliseconds in a week, then a week has passed and you set REEDCOUNT to zero and "week_begin_millis" to the value of "millis()" to begin a new week. Another method would be to set REEDCOUNT to zero at a fixed time each week (eg. Sunday at noon), using the RTC value already stored in "now".

could u pls write it in down? im very new. :)

Ossens:
could u pls write it in down? im very new. :slight_smile:

Better, you make your best attempt at using the recommendation and see if it works.
If it does not, post your code here with a description of how the actual results differ from your expected results.