Reset time and counter every minute

The problem is my if statement is not activating for some reason and I don't know how to make it activate. The first if statement in the loop section is the one not working.

So I have a geiger counter and a timer. Every minute, I want the amount of counts to reset, and an updated minute. I don't count about seeing the amount of millis() that have passed. For instance I want the output to be: Minute: 1 Counts: 6

Minute 2 Counts: 2

//definitions
int Geiger= 0;
int count = 0;
int minute =1;
unsigned long steptime;
const long interval = 60000;
unsigned long PastTime=0;
unsigned long CurrentTime=millis();
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
    if (CurrentTime >= 60000) {
     CurrentTime=PastTime;
      count=0;
      minute=minute+1;
      Serial.print("Minute:");
      Serial.println(minute);
    }
      unsigned long CurrentTime = millis();
    Serial.print("Time: ");
    Serial.println(CurrentTime); 
    if(Serial.available()>0) {
        Geiger=Serial.read();
        Serial.println(Geiger);
        Geiger=(Geiger-48);
        if (Geiger>0) {
        count+=1;
    }
  }

Serial.print("Counts: ");
Serial.println(count); 
}

Lose the "unsigned long" on line 22 (but not the rest of the line). That creates a new local variable and you already have that variable defined at the top of the program.

It looks like you have your Geiger counter connected to Serial as well as trying to use Serial for the Arduino Serial Monitor. That is only going to cause confusion. Assuming you are using an Uno use SoftwareSerial to make a separate serial for the Geiger counter.

Have a look at how to use millis() in several things at a time. The way you use it millis() will only be 60000 once every 49 days.

...R

This is also my problem. Were you able to solve it?

bruzlee: This is also my problem. Were you able to solve it?

Post the problem code and describe the problem

bruzlee: This is also my problem. Were you able to solve it?

And have you carefully studied the advice that was given 2 years ago? It is still relevant.

...R

Please help me about this. I want to reset the counter for every 5 seconds and i just modified this code.

// digital pin 2 has a ZapperInput attached to it. Give it a name:
int ZapperInput = 2; 
int ZapperState = 0;
int ZapperStateCounter = 0;

int seconds = 5;
unsigned long steptime;
const long interval = 5000;
unsigned long PastTime=0;
unsigned long CurrentTime=millis();


// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the ZapperInput's pin an input:
  pinMode(ZapperInput, INPUT);
}

// the loop routine runs over and over again forever:

void loop() {
//   read the input pin:

 int ZapperState = digitalRead(ZapperInput);
          // delay in between reads for stability

if (CurrentTime >= 5000) {
  CurrentTime=PastTime;
      ZapperStateCounter=0;
      seconds=seconds+5;
      Serial.print("Seconds:");
      Serial.println(seconds);
}
 if (ZapperState == HIGH){
      ZapperStateCounter++;
      delay(300);
      Serial.println(ZapperStateCounter);

      
  
  }}

You have lost the plot somewhere.

When using millis() for timing you should save the millis() value when a start action occurs. Then each time through loop() check whether the required period has elapsed by subtracting the start time from the current millis() value and act appropriately if it has.

Your code does not do this.

Have you read Using millis() for timing. A beginners guide, Several things at the same time and looked at the BlinkWithoutDelay example in the IDE.

bruzlee:
This is also my problem. Were you able to solve it?

Why did you not continue in your other thread?

sterretje: Why did you not continue in your other thread?

sorry, will do now

UKHeliBob:
You have lost the plot somewhere.

When using millis() for timing you should save the millis() value when a start action occurs. Then each time through loop() check whether the required period has elapsed by subtracting the start time from the current millis() value and act appropriately if it has.

Your code does not do this.

Have you read Using millis() for timing. A beginners guide, Several things at the same time and looked at the BlinkWithoutDelay example in the IDE.

Ok thanks, will apply those.