Do I need to use interrupts?

I'm trying to use a Pro Mini (5 volt) to measure how windy it is (to deflate an inflatable lawn penguin when it gets too windy). I built a sensor which catches the wind and generates a LOW for about 10 degrees of each rotation. I don't (think I) need instantaneous wind speed, just an average of, say, the last minute. If my code produces 1 to 4 results per minute that should be OK. I was going to use the FreqMeasure library but can't find out what pin to use for input, or even if my board is supported. From the author's forum, all it says is:

which pins should I use with the pro or nano?
Same as Arduino Uno.

If those nanos or minis are Chinese clones, just for fun why don't you try asking the sellers this question. It's always amusing to see what they say, if they even try to answer.

The only other mention (elsewhere on the web) that I found said something like only some/not many boards are supported by the FreqMeasure library .
I decided to just poll my sensor's status using digitalRead() for the state of the sensor and millis() for timing. The code will have no other things to do other than sense wind conditions. After a certain threshold is passed it will change a GPIO to HIGH (causing a relay to open its contacts) and continue monitoring the sensor status (I could just have it wait for some time after which it would effectively power cycle). When the coast is clear, the GPIO will return to a LOW state and Pen-gee (the inflatable lawn penguin) will rise again!
So my question is if interrupts will offer any benefits in this application. My understanding is that interrupts will give better measurements of instantaneous wind speed, but I figure that when averaging over an interval of approximately 15-60 seconds the code won't mind having to wait a fraction of a second here and there. Execution might be halted at arbitrary instructions, but the overall load to the processor should be the same. Interrupts don't actually speed things up, right?

Beavis4ever:
I'm trying to use a Pro Mini (5 volt) to measure how windy it is (to deflate an inflatable lawn penguin when it gets too windy). I built a sensor which catches the wind and generates a LOW for about 10 degrees of each rotation. I don't (think I) need instantaneous wind speed, just an average of, say, the last minute. If my code produces 1 to 4 results per minute that should be OK. I was going to use the FreqMeasure library but can't find out what pin to use for input, or even if my board is supported. From the author's forum, all it says is:The only other mention (elsewhere on the web) that I found said something like only some/not many boards are supported by the FreqMeasure library .
I decided to just poll my sensor's status using digitalRead() for the state of the sensor and millis() for timing. The code will have no other things to do other than sense wind conditions. After a certain threshold is passed it will change a GPIO to HIGH (causing a relay to open its contacts) and continue monitoring the sensor status (I could just have it wait for some time after which it would effectively power cycle). When the coast is clear, the GPIO will return to a LOW state and Pen-gee (the inflatable lawn penguin) will rise again!
So my question is if interrupts will offer any benefits in this application. My understanding is that interrupts will give better measurements of instantaneous wind speed, but I figure that when averaging over an interval of approximately 15-60 seconds the code won't mind having to wait a fraction of a second here and there. Execution might be halted at arbitrary instructions, but the overall load to the processor should be the same. Interrupts don't actually speed things up, right?

I would do the poll thing. make a poll, keep in mind your max frequency and according to that implement a "debounce" by making sure what you are reading on the pin (check for changeStatus). then you make an average.
then,after I got the average... Id go to interrupts.
it should work, remember the "old" approach was to generate a longer pulse with a ne555 and integrate with RC passives ! now you have a huge jump in technology to implement this !

Start with polling, it's not like your code is going to be doing other things. Do you need to debounce the signal?

wind speed doesn't change that quickly and polling should be more than adequate and easier to implement/test

proper averaging and hysteresis should result in reliable decisions once proper averaging rate and decision thresholds are determined.

shouldn't take more than a few lines of code

const byte InputPin = 2; // Whatever digital pin you want to use
const unsigned long DebounceTime = 30;


unsigned RotationCount = 0;
const unsigned ROTATION_LIMIT = 20; // Rotations in a 15-second period that cause shutdown


boolean InputIsActive;
boolean InputWasActive;  // Defaults to 'false'


unsigned long InputStateChangeTime = 0; // Debounce timer


void setup()
{
  Serial.begin(115200);
  pinMode (InputPin, INPUT_PULLUP);  // Input between Pin and Ground
}


void loop()
{
  unsigned long currentTime = millis();
  static unsigned long startTime = 0;


  InputIsActive = digitalRead(InputPin) == HIGH;


  // Check for Input state change and do debounce
  if (InputIsActive != InputWasActive &&
      currentTime  -  InputStateChangeTime > DebounceTime)
  {
    // Input state has changed
    InputStateChangeTime = currentTime;
    InputWasActive = InputIsActive;


    if (InputWasActive)
    {
      // Input was just Active
      RotationCount++;
    }
  }
  // Check the rotation count every 15 seconds
  if (currentTime - startTime > 15000)
  {
    startTime = currentTime;


    if (RotationCount > ROTATION_LIMIT)
    {
      // Do this stuff if too windy
    }


    RotationCount = 0;
  }
}

Beavis4ever:
From the author's forum, all it says is:

If your ProMini uses an Atmega 328 then the pins will be the same as for an Uno or nano.

...R

Beavis4ever:
I built a sensor which catches the wind and generates a LOW for about 10 degrees of each rotation.

Yes, this excatly the sort of thing where interrupts become reasonable.

Robin2:
If your ProMini uses an Atmega 328 then the pins will be the same as for an Uno or nano.

...R

Thanks for solving my problem at its root, this saves me from going down a lot of branches (the first one being to interrupt or not to interrupt). I used GPIO 8 which the UNO uses, and the library works like a charm! Not I can get the wind triggered kill switch working before the holiday season is over.
I should have gone to a reading comprehension forum instead because I posted the answer to my own question; it was in the link that I gave! I don't know what I had thought he meant by, "Same as Arduino Uno", I must have just glossed over it. Thanks for expanding on that statement, I know my question wasn't making the best use of your skills here, since you were acting more as a reading coach in my case. I'll try extra hard to eliminate any questions I have because of my reading skills before I make another post

PaulMurrayCbr:
Yes, this excatly the sort of thing where interrupts become reasonable.

I was able to get the FreqMeasure library working nicely which I understand does use interrupts, so all is well! Thanks for the advice :wink:

wildbill:
Start with polling, it's not like your code is going to be doing other things. Do you need to debounce the signal?

I was able to get the FreqMeasure library working, so I don't have to go that route. I am using an optical sensor which doesn't seem to have a problem with bounce. When I do use mechanical switches I like to use hardware for debouncing the contacts (i.e. a capacitor across the switch's terminals).