Counting on/off pulses independently.

I'm working with a weather station that uses a wind vane and an anemometer. i am using an Ethernet shield to connect to my database to store the information that i send from my arduino.

Anyways, i have programmed my arduino to correctly tell me if the wind vane is facing whichever direction. My problem is the anemometer.

According to the Datasheet:

The cup-type anemometer measures wind speed by closing a contact as a magnet moves past a switch. A wind speed of 1.492 MPH (2.4 km/h) causes the switch to close once per second.

i understand that 1 on/off per second is equal to 1.492MPH. Its not a problem calculating x speed by counting the ammount of on/off by cross multiplying.

the thing is that i've searched a few forums for a way to do this but they arent exactly what im looking for. All their examples make my delay last more than one second (my loop MUST have a delay of 1 second).

How can i go about counting the on/off without interfering with my main delay? I hope you guys understand my question. Thanks in advance! :D

You need to never use delay. Use the millis timer to record the first contact and then on the second contact record the time again. Then the difference between the two readings is the time for your revoloution. Then convert that to your MPH reading.

Post your code for more help. Use code tags or else you might not get any.

Grumpy is right, there is 0 need for a delay...

Delaying your code by 1 second before every reading will make your program completely useless...

Just hook the wind meter to an interrupt on a rising edge, when it triggers then take the difference from the last reading and convert like Grumpy said...

bathtubbuddy: According to the Datasheet: i understand that 1 on/off per second is equal to 1.492MPH. Its not a problem calculating x speed by counting the ammount of on/off by cross multiplying. ... the thing is that i've searched a few forums for a way to do this but they arent exactly what im looking for. All their examples make my delay last more than one second (my loop MUST have a delay of 1 second).

Why do you "MUST have a delay of 1 second"?

What do you want to do? Measure wind in time slices of 1 second?

What's the lowest wind speed you want to detect?

Let's think of the following: The wind is slow and your anemometer counts 5 on/off events in 10 seconds.

Now what will happen if you measure wind in 1s time slices: 1st second: no on/off ==> 0.000 MPH 2nd second: 1 on/off ==> 1.492 MPH 3rd second: no on/off ==> 0.000 MPH 4th second: 1 on/off ==> 1.492 MPH and so on.

You see what happens on slow wind speeds and 1s time frames: The actual wind speed is 0.746, but you always measure either 0.000 or 1.492.

Is that what you want to happen at slow wind speed? And then somehow 'smoothen' your raw data with some averaging?

But look what averaging does: If you average using 2 values: (0+1.492)/2 = 0.746 (correct average) If you average using 3 values: (0+1.492+0)/3 = 0.497 (wrong average) So averaging may lead to averaging errors, depending on the actual values and on how many values you take for averaging.

The actual wind speed is not dependent on exact one-second-intervals, but the wind speed depends on the time difference of two on/off events. To detect that, you'll need interrupt programming and the reed contact of the anemometer has to be connected to an interrupt enabled pin.

With an Atmega328 based board (like UNO), the pin numbers 2 and 3 are hardware interrupt enabled. So first check what interrupt enabled pin on your board you may be able to use, then create an interrupt handling routine on RISING or FALLING edge.

Ah ok guys i seee. So basicly, the readings i should seee, are averages? ill give that a shot. Sorry for not responding, i was super busy with work last week. No chance to work on this project.

I made an application in visual studio which would control the intervals of when the Arduino would send the information to the database. That's reason i had the delay (i was thinking of leaving it at 1 second as default.) Ill have to remove that since i want it to work the best as possible.

I forgot to mention that i'm a little new to programming microcontrollers.