Wind Speed Sensor detection code

Dear all,

I need simple code to detect the pulse output coming from this sensor. I also need additional circuit to detect the pulse when it has been connected to interrupt pin. Because I found variation in output.

//volatile unsigned int pulses=0;
static int pulses=0;
unsigned long button_time = 0;  
unsigned long last_button_time = 0; 
int pin=8;
void setup() {
  attachInterrupt(1, countpulses,RISING); // interrupt 0 = pin 2 
   
  Serial.begin(9600);
}

void loop() {
  
 /* int count=0;
  count=pulses+1;
   Serial.println("count is");*/
   //Serial.println(pulses);
  /*Serial.println("\n");*/
  //delay(1000);
 
  
}

void countpulses() {
   button_time = millis();
   if(button_time - last_button_time >50){
     if(digitalRead(pin)==1){
        pulses=pulses+1;
     
      }
  else
  {
    pulses=pulses-1;
  
  }
    last_button_time = button_time;
    Serial.println(pulses);
  }
  
  
 
  
}

wind speed Sensor WS120 pulse.pdf (80.2 KB)

attachInterrupt(1, countpulses,RISING); // interrupt 0 = pin 2

Which interrupt are you actually using ?

Do you really want the pulses variable to be static ? Should it not be volatile ?

    Serial.println(pulses);Does this work in an ISR ?

UKHeliBob:

attachInterrupt(1, countpulses,RISING); // interrupt 0 = pin 2

Which interrupt are you actually using ?

Do you really want the pulses variable to be static ? Should it not be volatile ?

    Serial.println(pulses);Does this work in an ISR ?

I am using interrupt pin 2 as Hardware .YES i want to calculate wind sensor for exactly 5 min.

What board are you using ?
Check which interrupt you are attaching the ISR to.

What has the 5 mins go to do with anything ?

UKHeliBob:
What board are you using ?
Check which interrupt you are attaching the ISR to.

What has the 5 mins go to do with anything ?

I want to carryout the test for Every min or 5 min . I am using Arduino UNO board.

Here what i want to expect. If interrupt is attached only the Increment has to be taken , Else should not read anything

You are using a Uno
The Uno has 2 hardware interrupts
Interrupt 0 is on pin 2. Interrupt 1 is on pin 3 http://arduino.cc/en/Reference/AttachInterrupt
attachInterrupt() takes the interrupt number as its first parameter
Your code isattachInterrupt(1, countpulses,RISING); // interrupt 0 = pin 2
Therefore you are using interrupt 1
Using the information above you will see that interrupt 1 is on pin 3
You say that you are using pin 2
Something is wrong