i use arduino meg+reed switch sensor to count rainfall.. the resolution is 0.2 mm.. i use this code :
const int REED = 4; //output reed switch di pin 9
int val = 0; //nilai arus pada reed switch
int old_val = 0; //nilai dari reed switch yang lama
float REEDCOUNT = 0; //This is the variable that hold the count of switching
void setup(){
Serial.begin(9600);
pinMode (REED, INPUT_PULLUP); //mengaktivasi pull up pada internal resistor
}
void loop(){
val = digitalRead(REED); //baca status pada reed switch
if ((val == LOW) && (old_val == HIGH)){ //cek jika terjadi perubahan status pada reed switch
delay(10); // Delay put in to deal with any "bouncing" in the switch.
REEDCOUNT = REEDCOUNT + 0.2; //Add 1 to the count of bucket tips
old_val = val; //Make the old value equal to the current value
Serial.print("Hujan = ");
Serial.print (REEDCOUNT); //Output the count to the serial monitor
Serial.println(" mm");
}
else {
old_val = val; //If the status hasn't changed then do nothing
}
}
i would to count rainfall every 3 hours and display it to serial monitor.. 00:00 , 03:00 , .......etc
after 3 hours, the value of sensor will reset,back to 0 and start to count.
and at 24:00/00:00 ,, arduino calculate sensor value for 24 hours...
can anybody help me.?? what function should i use..??
the value of sensor will reset,back to 0 and start to count.
Nonsense. The sensor will continue forever to sense rain. It is the number of times that you have counted that it has sensed rain that you want to reset.
Perhaps, thinking about it this way has made what you need to do clearer.
If you want to count the number of times during some interval, you have to know when the interval starts, and when the interval has elapsed. You don't have anything in your code that knows anything about WHEN an event happens.
If you want to reset a counter at midnight, you have to know when midnight is. The Arduino is NOT a clock. You need to add an external RTC.
PaulS:
If you want to reset a counter at midnight, you have to know when midnight is. The Arduino is NOT a clock. You need to add an external RTC.
Unless you can be happy with readings every 3 hours, but not synchronized with the clock. So if you apply power to the board at 01:33, your next reading would be at 04:33 and so on... just use millis() timing and an interval of 36060*1000 milliseconds.
Unless you can be happy with readings every 3 hours, but not synchronized with the clock. So if you apply power to the board at 01:33, your next reading would be at 04:33 and so on... just use millis() timing and an interval of 36060*1000 milliseconds.
Today, we got 2.5 inches of rain. Well, between 1:33:00 AM Tuesday and 1:32:59 AM Wednesday, anyway.