Multiple buttons and multiple counters (with rain gauges)

Hi all,

I`m new here and also a novice with Arduino....

I'm trying to count several tipping buckets (rain gauge) in a project with one arduinoboard
You can see it as 5 buttons on 5 digital inputs. Every input needs to be counted independently.

The arduinoboard is doing also some other measurements, but I try to build this sketch from scratch where I can count the 5 buttons (with 5 counters).

Can I check these 5 buttons independently from the main loop (where the mainloop repeats every 7 seconds for another measurement and displaying reasons)

I really don't know how to start building up this sketch.

Can anyone give me a hint or a link ?
I spended allready many hours to find a good example online...

thanks in advance !
Jimmy

This is a try with 3 inputs (buttons) on a Arduino Uno
Should I use interrupts to make this independently from main loop ?

int state7=LOW;
int state8=LOW;
int state9=LOW;
int lastState7=LOW;
int lastState8=LOW;
int lastState9=LOW;
int count7=0;
int count8=0;
int count9=0;

void setup(){
Serial.begin(9600);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
state7=digitalRead(7);
state8=digitalRead(8);
state9=digitalRead(9);
}
void loop(){
if (state7==HIGH && lastState7==LOW){
count7++;
Serial.print(count7);
Serial.print("\t");
Serial.print(count8);
Serial.print("\t");
Serial.println(count9);
}
if (state8==HIGH && lastState8==LOW){
count8++;
Serial.print(count7);
Serial.print("\t");
Serial.print(count8);
Serial.print("\t");
Serial.println(count9);
}

if (state9==HIGH && lastState9==LOW){
count9++;
Serial.print(count7);
Serial.print("\t");
Serial.print(count8);
Serial.print("\t");
Serial.println(count9);
}


lastState7=state7;
lastState8=state8;
lastState9=state9;
state7=digitalRead(7);
state8=digitalRead(8);
state9=digitalRead(9);
delay(20);
}

Hi,

Your tipping buckets, do they send a pulse in each tip, or have a 1 output say tipped to the left and 0 output when tipped to the right.

If pulses, you may have to use interrupts so that you do not miss a pulse while doing something else in your sketch.

Tom.... :slight_smile:

The tipping bucket is like a pushbutton. Every push needs to be counted.

jmo2300B:
Should I use interrupts to make this independently from main loop

Do a search for 'several things at a time'. Also try to understand the BlinkWithoutDelay example.

It should give you an idea how to read buttons while the loop is mainly doing other work; no interrupts needed unless the main funtion of loop() is a calculation that takes 7 seconds.