Can Not retrive revolution data for Anemometer (wind speed)

I found a code for my weather station.
Link: SEN-08942

The applications (rain gauge, anemometer, and wind vane) are same as the pictures shown in the link.
For the circuit, I used only wires and resistors, as the note said.
However, my problem is that I could never get revolution data.
The wind vane works, but the rain gauge and the anemometer did not.
The screen always show zero (see attachment).

Down bellow is my code for wind speed and rain gauge.
I gather data every 5 seconds and average wind speed.

For wind speed:

/*  The SEN-08942 is an anemometer, wind vane and rain gauge set for prototyping an amateur 
     weather station.
    For its complement map SparkFun Weather Shield. 
/* From */

/* Arduino sketch for Weather device from Sparkfun.
  Uses only the wind direction vane and the anemometer (not the rain gauge).

  Although the inclination for a weather logger is to run it for
  a long time, due to the way Wiring.c implements the millis() function,
  this should be restarted, oh, monthly. The millis() functions overflows
  after about 49 days. We could allow for that here, and handle the
  wraparound, but you've got bigger problems anyway with the delay()
  function at an overflow, so it's best to "reboot".

  This is connected to Arduino ground on one side, and pin 2 (for the
  attachInterrupt(0, ...) on the other.
  Pin 2 is pulled up, and the reed switch on the anemometer will send
  that to ground once per revolution, which will trigger the interrupt.
  We count the number of revolutions in 5 seconds, and divide by 5.
   1 Hz (rev/sec) = 1.492 mph = 2.40114125 kph = 2401.1 m/h

                  WIND DIRECTION VANE
  We use a classic voltage divider to measure the resistance in
  the weather vane, which varies by direction.
  Using a 10K resistor, our ADC reading will be:
      1023 * (R/(10000+R))
  where R is the unknown resistance from the vane. We'll scale
  the 1023 down to a 255 range, to match the datasheet docs.

                    >     10K
                    <   Resistor
  Analog Pin 5------|
                    -----------| To weather vane
                               | (mystery resistance)
  The ADC values we get for each direction (based on a 255 max)
  follow, assuming that pointing away from the assembly center
  is sector zero. The sector number is just which 45-degree sector
  it is, clockwise from the "away" direction. The direction
  shown is assuming that "away" is West. Depending how
  you orient the system, you'll have to adjust the directions.

      Sector   Reading  Direction
        0        18        W
        1        33        NW
        2        57        N
        7        97        SW
        3       139        NE
        6       183        S
        5       208        SE
        4       232        E
  The values in the ADC table below list the midpoints between
  these, so our reading can vary a bit. We'll pick the first value
  that's >= our reading.
                  RAIN GAUGE
  Implemented here.
  It is done the same way as the anemometer, and use
  attachInterrupt(1, ...) on pin 3. Each interrupt represents
  .011 inches of rain (0.2794 mm), according to the docs.

#define PIN_ANEMOMETER  2     // Digital 2 for anemometer (wind speed)

/* How often we want to calculate wind speed or direction
   每隔 5sec = 5000ms 紀錄風速數據 */
/*================== Declare Variables ==========================*/
volatile int numRevsAnemometer;  // Incremented in the interrupt
                                 // For interrupt use volatile to avoid failure
unsigned long nextCalcSpeed;     // 下一次計算平均風速的 時間點
unsigned long time;              // Millis() at each start of loop()

/*================== Declare Functions ==========================*/
void countAnemometer();
void calcWindSpeed();
/*================== Initialize =================================*/
void setup() {
   digitalWrite(PIN_ANEMOMETER, HIGH);
   attachInterrupt(0, countAnemometer, FALLING);// Interrupt 0 在 pin 2 上   
   nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
   Serial.println("setup ready");   
   Serial.println("Please wait for 5sec...\n");
   Serial.println("Revolutions\t Wind speed (m/h)");

/*================== Main loop ==================================
 * 間隔 MSECS_CALC_WIND_SPEED (5sec) 後,呼叫function: calcWindSpeed() 得到 風速數據
 * 下一次取得 風速數據 的時間點: 再過 5sec 後
void loop() {  
   time = millis();
   if (time >= nextCalcSpeed) {
      nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;

/*=============== countAnemometer() =============================
 * Interrupt handler for anemometer. Called each time the reed
 * switch triggers (one revolution).
void countAnemometer() {

/*=============== calcWindSpeed() ===============================
 * Calculate the wind speed, and display it (or log it, whatever). 
 * 1 rev/sec = 1.492 mph = 2.40114125 kph = 2401.1 m/h
void calcWindSpeed() {
   int x,r, iSpeed; // x = 整數,r = 小數
   // This will produce: m/h * 10
   // (didn't calc right when done as one statement)
   long speed = 24011;
   speed = speed*numRevsAnemometer/MSECS_CALC_WIND_SPEED;
   iSpeed = speed;         // Need this for formatting below
   x = iSpeed / 10;
   r = iSpeed % 10;
   Serial.print(numRevsAnemometer); Serial.print("\t\t "); Serial.print(x); Serial.print('.'); Serial.println(r);

   numRevsAnemometer = 0;        // Reset counter

For Rain Gauge:

#define MSECS_CALC_RAIN_FALL  5000         // 5sec
volatile int numDropsRainGauge = 0;
unsigned long nextCalcRain;
unsigned long time;
void setup() {
   attachInterrupt(digitalPinToInterrupt(PIN_RAINGAUGE), countRainGauge, FALLING);
   nextCalcRain = millis() + MSECS_CALC_RAIN_FALL;
   Serial.println("setup ready");

void loop() {
   time = millis();
   if(time >= nextCalcRain) {
    nextCalcRain = time + MSECS_CALC_RAIN_FALL;

void countRainGauge(){

void calcRainFall(){
  float Rain = 0.279400;
  Rain = Rain*numDropsRainGauge;
  Rain = Rain/MSECS_CALC_RAIN_FALL*1000; //mm per sec

  Serial.print("Rain fall(mm/sec):\t");Serial.println(Rain);
  numDropsRainGauge = 0; 




I tried another code, but still in vain.
How to Hookup Davis Anemometer to Arduino (Part 2 of 3)

I do notice that there should not be any time function in the ISR function. But I couldn’t figure out how to change the code (the part that included debounced).

My other code:

#include <math.h> 

#define WindSensorPin (2) // The pin location of the anemometer sensor 

volatile unsigned long Rotations; // cup rotation counter used in interrupt routine 
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine 
float WindSpeed; // speed miles per hour 

void setup() { 
  pinMode(WindSensorPin, INPUT); 
  attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING); 
  Serial.println("Davis Wind Speed Test"); 

void loop() { 
  Rotations = 0;  // Set Rotations count to 0 ready for calculations 
  sei();          // Enables interrupts 
  delay (3000);   // Wait 3 seconds to average 
  cli();          // Disable interrupts 
  /* convert to mp/h using the formula V=P(2.25/T) 
     V = P(2.25/3) = P * 0.75 */
  WindSpeed = Rotations * 0.75;  
  Serial.print(Rotations); Serial.print("\t\t");Serial.println(WindSpeed); 

// This is the function that the interrupt calls to increment the rotation count 
void isr_rotation () { 
  if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact. 
    ContactBounceTime = millis(); 

I’m totally confused!
Why couldn’t I get the revolts for wind speed and rain drops for rain gauge?

The code you posted (correctly; thank you for that) does something, but you didn't say what it actually does. You expect each sketch to do something, but it isn't clear what you expect it to do.

The code you posted (correctly; thank you for that) does something, but you didn’t say what it actually does. You expect each sketch to do something, but it isn’t clear what you expect it to do.

Well… I was excepting that the monitor will show the wind speed [meters per second] and revolutions every 5 seconds.But the result shown in the monitor is zero.

There is a switch inside the wind vane. So, every time the vane spins (due to wind blow), it will click on and off the switch. Therefore, I use attachInterrupt() function.

It should be gathering the revolution every 5 seconds, then multiple 2401.1 [m/(hr*revolt)].
And lastly, average it (divide 5 ) to get the average wind speed [m/hr].

There’s also a switch inside the rain gauge. It counts how many time it flips on/off (implies how many rain drops), and then calculate the average rainfall during 5 seconds [mm/sec].

I printed the revolution just to make sure the program works, but it didn’t.
I made 3 attempts, all of them using attachInterrupt function.
Two with different code for wind speed. And one for rain gauge.
But the result shown in the monitor is zero.

I’m not sure whether there’s a false code line inside the program or something else.

The program is a little… huge… So, I’m now trying to dividing into small pieces and use a button switch to test the program again.

Do the wind speed and rain sensor switches have external pullup resistors installed? If not, try enabling the internal pullups, in setup(), using pinMode(pin, INPUT_PULLUP). External pullups (10K to 1K) may be necessary to deal with noise picked up by long wires.

groundFungus: Do the wind speed and rain sensor switches have external pullup resistors installed? If not, try enabling the internal pullups, in setup(), using pinMode(pin, INPUT_PULLUP). External pullups (10K to 1K) may be necessary to deal with noise picked up by long wires.

The code works fine, after I tested with a switch button. I think it's the circuit problem. The problem for the rain gauge is that the voltage supplier should be 3.3V, not 5V.

However, the anemometer won't work (circuit problem again, I suppose).

Anyway, thanks for your suggestion.