// LED pin
int ledPin = 13;
float sig_Rain = 0; // Rain guage sensor variable
int tip_cnt = 0; // Count the tips
void setup ()
{
Serial.begin(9600);
// Turn off onboard LED off
// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn the LED on (HIGH is the voltage level)
Serial.println("Rain_guage_signal");
}
void loop ()
{
// Collect Raing guage sensor data
sig_Rain = analogRead(sig_rain)*5.0/1024.0;
// Print the raing guage
//Serial.print(sig_Rain,4);Serial.print(",");
// Counter
if(sig_Rain<5.0){
if(sig_Rain>4.9){
if(sig_Rain<5.0){
tip_cnt = tip_cnt+1;
}
}
}
Serial.print(tip_cnt);Serial.print(",");
Serial.println();
}
Present output:
Counter is zero. Looks like I am comparing present samples, but I have to compare previous samples. How do I do that?
Measure each HIGH duration (make a note of millis when you see a LOW to HIGH transition and when the reading goes to LOW calculate how long it stayed HIGH) and decide if it's a keep or not based on some threshold
The problem is, it counting each instance. I want consider this whole duration as 1 count. The reason is, my sensor gives 5 V output when bucket is full, and it tips automatically by itself and next time it gives 5 V output when bucket is full again. This continues. I am counting here the number of times bucket tips.
1. Can you give an idea of 5V duration in ms, which will not be considered as a spike? For example: a signal between 4.5 V - 5V of > 1 ms duration would be considered as 5V and hence 1 count.
2. According to my above definition, there are 3 counts in the signal of Fig-1.
Figure-1:
3. Create a sketch to scan the signal of Fig-1 and show 3 on the Serial Monitor.
Thanks for referring it. I implemented it as it is with no changes. Looks like it stops at 1 because it compares only previous state. In my case, I may have to compare many samples before.