Hi All
I am struggling to devise a coding solution for arduino that will allow me to read the liquid precipitaion in that last 24 hours. I have used the following code to detect tipping via a digital interrupt but I can’t see how to produce a moving sum. Does it require a real time clock?
Any help is apprechiated.
Thanks in advance
int pulsePin =3;
unsigned long counter = 0;
unsigned long duration = 0;
unsigned long timeout = 1000000; // in microseconds
void setup() {
pinMode(pulsePin, INPUT);
// enable the 20K pull-up resistor to steer
// the input pin to a HIGH reading.
digitalWrite(pulsePin, HIGH);
Serial.begin(9600);
}
void loop() {
duration = pulseIn(pulsePin, HIGH, timeout);
if (duration == 0) {
Serial.print(“Pulse started before the timeout.”);
Serial.println(“”);
} else {
counter++;
//Serial.print(counter);
// Serial.print(", ");
Serial.print(duration*.000001);
Serial.println(" s");
//Serial.println(“”);
Serial.print (counter*.2794);
Serial.println(" mm");
}
}
Yes, you need to keep track of time. The arduino library does provide some functions to help you with that; if you aren’t super picky about accuracy and you don’t care about date/time-of-day, this can be as simple as using the millis() function to time your data.
I’m not picky about time. I just don’t know how to program even the basics of this. Please help if you know.
If you have to do the calculations on the Arduino, you don’t have enough memory to do a real 24-hour moving sum, because you can’t keep track of 24 hours of bucket tips on a big rain day (well, maybe if you’re some place where it never rains more than an inch in 24 hours). But you can divide time up into some reasonable number of chunks (e.g., 24 one-hour chunks), and record bucket tips in those chunks. You need to keep track of the start time for each chunk so you know when to start over on the count (i.e., you are about to add to the count for hour 3, but first you check to see if the count in hour 3 belongs to the current day or 24 hours ago, and start over if it has expired).
Hope this helps–sounds like it should be a fun project.