Reading Anemometer Pulses

I am using a simple Inspeed anemometer (sensor only). They offer software but what fun is that? The model claims to output 1 pulse per 2.5mph of wind speed through a two wire hook up. I tried to hook it up to a digital pin and use the PulseIn function, but the PulseIn only returned a "0" no matter what speed I twisted the anemometer.

I hooked it up to an analog pin and with labview the output has the following characteristics after a test spin of the anemometer:

The magnitude seems to vary around 2 volts.

What is the easiest way to get the pulse frequency? LabView code? Because I was hoping the Arduino would give me a pulse long value and then my day is easier.

Could try a falling edge interrupt.

How exactly do you have the sensor connected to the analog input? From the labview trace it looks like you have one wire of the sensor connected to an analog input and the other connected to ground and the input is just floating up to some level and then returns to 0 volts when the reed switch closes. I would think you needed a pull-up resistor on the input whether analog or digital.

Also, the sensor output is 2.5 mph per Hz(pulses per second), not per pulse.

It was connected to gnd. How do you recommend I hook up the pull up resistor?

You would attach a resistor, say 10k, from the analog or digital input pin to your logic supply voltage, 5V or 3.3V for the Arduino. One of your sensor leads would also be attached to this pin. Then the other sensor lead would go to ground.

The resulting signal may need to be debounced but the first step is to interface the sensor properly.

Shouldn't need any debouncing. But you should use one the the digital input pins not an analogue one if you want to use the pulse in function.

Use a voltage comparator (like, say, half of an LM393) to turn that sawtooth into a square wave. Since you're measuring frequency, not pulse width, it doesn't matter much where you set the threshold. You'll want it close to 1V, to getter better noise immunity, but not so high that you miss some pulses.

It would be better if you can put the comparator close to the anemometer, because then you'll be sending a strong 5V-peak signal down the wire, instead of a 1V-peak one that might be more susceptible to interference from noise.

Ran

This sensor is just a reed switch and a magnet, therefore, I don't think that sawtooth is a normal output from it.

First, thanks for the responses.

Here is the straight analog output now with the sensor wired as EmilyJane described (~0.5 to 1 sec of data):


Looks a lot better!

When connected to the digital pin of the Arduino with PulseIn the output looks like this:

The middle value (0 - 30) is from PulseIn. Here is the code associated with that:

float windvanevalue = 0;
float windvanevolts = 0;
unsigned long duration;

void setup()
{ 
    Serial.begin(9600);
    pinMode(7,INPUT); 
} 


void loop()
{
  duration = pulseIn(7, LOW);

  windvanevalue=analogRead(5);                   
  windvanevolts=windvanevalue*5/1024;

  Serial.print("F ");                               
  Serial.print(duration);
  Serial.print(" ");
  Serial.println(windvanevolts);                   
    
  delay (5);
}

At this point I can use Labview to get a frequency, but I really want to use the PulseIn function. The problem is that it never exceeded 30, and stayed around that number no matter what anem. speed. Is this because the signal is still not conditioned well enough?

I don't see anywhere where you're measuring a frequency.

You're measuring the "low" part of the pulse, but that is not the frequency.

The frequency is the inverse of the period between one time the signal goes low (or high), and the next time it goes low (or high).

My trusty ruler leads me to believe you must be getting some bounce from the reed switch. If the LOW part of your waveform is 30 microseconds as your printout suggests, then the frequency from your labview .vi display is around 6KHz, which doesn't sound likely.

You can debounce in software or use a one-shot if you are more comfortable with hardware. Then you will need to measure the whole period of your waveform as AWOL suggests.

The low part of the signal is the time the magnet passes the sensor, the high part of the signal is the time taken for it to come round again. So the high part is going to be more sensitive to the speed. So use pulse in to measure the low part.

To get the speed one has to measure the period, as AWOL has pointed out, not just the HIGH part or the LOW part.

No read what I said.

The period is the sum of the up and down parts, however the ratio of up to down is constant. Therefore you only need to measure one of them.

If you are trying to say that it is only necessary to measure the time between when either of them starts or ends, then you are correct. That is the definition of period.

What exactly did you mean when you said that "...the high part is going to be more sensitive to the speed."?

The notion that the ratio of LOW to HIGH pulse widths is constant seems incorrect. Even if it were, how would you determine the ratio? Would you mind illustrating with a small snippet of code?

I'm curious if you found a solution for reading the Inspeed anemometer pulses. I am looking for an inexpensive anemometer to trigger events based on wind speed and that looks like it would do the trick if it can be made to work with the Arduino. If you have found a solution, would you mind posting related code and/or wiring schematic required to make it work?

Well I had it working but have a problem now. The anemometer (a reed switch?) has two wires, and I have one connected to 5V and the other to a digital input pin - more on that below.

/*
Analog Input for 2 Anemometers and Wind Vanes
*/


long pulsewidth1;
long pulsewidth2;
float wspeed1;
float wspeed2;

void setup()
{ 
    Serial.begin(9600);
    pinMode(8,INPUT);  //Anemometer 1
    pinMode(7,INPUT);   //Anemometer 2
} 


void loop()
{
  pulsewidth1=pulseIn(8, LOW);  //Anemometer 1
  pulsewidth2=pulseIn(7, LOW);   //Anemometer 2

//Formula for period (in microsec) to mph
  wspeed1=1000000.0/pulsewidth1*2.5;
  wspeed2=1000000.0/pulsewidth2*2.5;

  Serial.print(wspeed1); 
  Serial.print(" ");
  Serial.println(wspeed2); 

  
  delay (5);
}

The problem is that it only works reliably for some reason with digital pin 13 (the one connected to a 1K resistor and led in parallel). Because I have two anemometers, I planned on using digital pins 7 and 8, which I then connected in parallel to a 1K resistor and 5mm led (on a protoboard). My serial output is mostly crap, returning exactly a period of 1, 2, or 3us randomly and only occasionally a period that makes sense (~tens of thousands of microsecs).

Why is my input different between digital pin 13 and 7/8? Is a debouncing capacitor the way to go now for this shaky result?

Can you post a schematic of your setup? If I understand how you have the anemometer hooked up, there seems to be a problem with that.

Pin 13 has a resistor (and LED) connected as a pull-down. See this thread for information on pull-up and pull-down resitors: http://www.arduino.cc/en/Tutorial/DigitalPins

You can connect an external resistor (10k is a common value) from the pins you want to useconnected to ground.

-Using a 1K pulldown (w/ LED) because the other anemometer is connected to 5V. Which is better for the pulsein function - changing this to 10K (would have to omit useless LED then) or go with the debouncing capacitor route?