Hi,
I got the following sensor with hall effect sensor on it
http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-Hall-Sensor-V2Hall.htm
I was wondering that do I need any kind of debouncing circuit with it to test with Arduino UNO.
Erica
Hi,
I got the following sensor with hall effect sensor on it
http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-Hall-Sensor-V2Hall.htm
I was wondering that do I need any kind of debouncing circuit with it to test with Arduino UNO.
Erica
If you get "8 Pulses per revolution" then ...
with hall effect sensor on it .....do I need any kind of debouncing circuit
Hall sensors do not require debouncing. The output signal typically requires a 5v pullup but I did not see any specifications or information on the website.
mrsummitville:
If you get "8 Pulses per revolution" then ...
- Hook it up to the Arduino
- Increment a Variable for each Low->High transition
- Spin it exactly 5 revolutions
- Display the Variable
- If the Variable is equal to 40 (within +/- 1 count) then no debounce is needed.
You are right, I do not need to do debounce. But when the speed of the air increases then it becomes difficult for the micro to handle it. I am using the following code that I got from the Ardunio forum
float windspeed; // wind speed
unsigned long start, duration;
int updated = 0; // <<<<-------- flag
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT); //reads the input from pin 2
attachInterrupt( 0, wspeed, RISING );
start=millis();
delay(20);
}
void wspeed()
{
duration = millis() - start;
start = millis();
if ( duration > 20 )
updated = 1;
}
void loop()
{
if (updated == 1)
{
Serial.print (" duration of the one turn ( msec ) : ");
Serial.println ( duration );
Serial.print ("windspeed : ");
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
Serial.print (windspeed);
Serial.println (" m/s");
delay(500);
updated = 0; // <<<<<---- reset a flag, so it woudn't print "old data".
}
else if (updated ==0)
Serial.print (" Not ready");
Serial.print("\n");
}
I read somewhere that I need to do the IRQ to handle this kind of sensor interface. Can someone guide to a piece of code that I can use to solve this problem plus how can I change meter/sec to miles per hour in this code that I posted? Or should I use an external rising edge triggered flip flop to do this?
One thing you need to do is to declare any variables that are modified inside the ISR as 'volatile':-
volatile unsigned long start, duration;
Converting metres per second to miles per hour shouldn't be too difficult:-
metres per second x 3600 = metres per hour.
(metres per hour)/1000 = km per hour, (kph).
kph x 0.621371 = miles per hour, (mph).
Using interrupts, an Arduino should have no problem doing this without the use of an external rising-edge-triggered flip-flop.
OldSteve:
One thing you need to do is to declare any variables that are modified inside the ISR as 'volatile':-volatile unsigned long start, duration;Converting metres per second to miles per hour shouldn't be too difficult:-
metres per second x 3600 = metres per hour.
(metres per hour)/1000 = km per hour, (kph).
kph x 0.621371 = miles per hour, (mph).Using interrupts, an Arduino should have no problem doing this without the use of an external rising-edge-triggered flip-flop.
Hi ,
becomes
windspeed = (( 2.5 * 1000.0 / (float) duration )*(0.447)) x 3600;
Am I right?
IRQ is a generic term. It just means "interrupt request".
Any interrupt generates an IRQ, then the ISR, "interrupt service routine", services it.
You're using the right type of interrupt.
The first thing to do, as mentioned, is to declare those variables as 'volatile', then go from there. Don't even bother with the conversion to mph until everything else works properly. That part is trivial and can be added later.
- windspeed = ( 2.5 * 1000.0 / (float) duration )(0.447);
becomes
windspeed = (( 2.5 * 1000.0 / (float) duration )(0.447)) x 3600;
That converts metres per second to metres per hour.
Divide that by 1000 and you have km per hour.
Multiply the result by 0.621371 and the result will be miles per hour.
If you spend some time thinking about it, you could create a better initial formula without going through all of those individual steps, but you will have to do it yourself or hope that someone else helps. I really don't feel like messing around with transposing/re-arranging formulae right now. I'm doing other things.
I was just trying to give you a basic guideline to work from.
If you do need to debounce the signal, go to playground.arduino.cc - plenty of methods to choose from.
OldSteve:
IRQ is a generic term. It just means "interrupt request".
Any interrupt generates an IRQ, then the ISR, "interrupt service routine", services it.
You're using the right type of interrupt.
The first thing to do, as mentioned, is to declare those variables as 'volatile', then go from there. Don't even bother with the conversion to mph until everything else works properly. That part is trivial and can be added later.
That converts metres per second to metres per hour.Dicide that by 1000 and you have km per hour.
Multiply the result by 0.621371 and the result will be miles per hour.If you spend some time thinking about it, you could create a better initial formula without going through all of those individual steps, but you will have to do it yourself or hope that someone else helps. I really don't feel like messing around with transposing/re-arranging formulae right now. I'm doing other things.
I was just trying to give you a basic guideline to work from.
Hi,
How can I confirm that everything is working? I did define the variables as volatile. Did you mean that
windspeed =( (( 2.5 * 1000.0 / (float) duration )*(0.447)) x 3600) x 0.621371; will give windspeed in miles/hour
Erica1989:
Hi,How can I confirm that everything is working? I did define the variables as volatile. Did you mean that
windspeed =( (( 2.5 * 1000.0 / (float) duration )*(0.447)) x 3600) x 0.621371; will give windspeed in miles/hour
No, you still didn't convert metres per hour to km per hour before converting kph to mph.
(((( 2.5 * 1000.0 / (float)duration )*0.447) * 3600.0)/1000.0) * 0.621371
Do you see how silly this now looks? That was just a guide. You need to re-write the formula so that it's more sensible. It could be simplified considerably.
For starters, 2.5*1000.0 = 2500.0. Write it all out on paper, then work out how to simplify the rest. (Remember pencils and paper?)
It's almost midnight here now - I'm exhausted and on the way to bed.
Edit: As I suggested, before messing around converting to miles per hour, which only complicates things, first get your code working properly in metres per second. Once you've done that, then worry about converting to other units. You're making things harder for yourself than they need to be.
Erica, could you please show me where you got this formula:-
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
Then in the morning, I'll work out a simple formula for you. ![]()
OldSteve:
Erica, could you please show me where you got this formula:-windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);Then in the morning, I'll work out a simple formula for you.
OP said:
I am using the following code that I got from the Ardunio forum
No mention of calibration for any particular anemometer.
aarg:
OP said: "I am using the following code that I got from the Ardunio forum"
No mention of calibration for any particular anemometer.
I just tracked it down. It's simple, (for the Vortex that she says she's using).
It's almost too easy for words.
The anemometer produces 1Hz at 2.5mph.
ie duration = 1000 @ 2.5mph. (duration in mS)
Therefore, the real formula is: mph = 2500/duration
Vortex Wind Speed Sensor
Edit: I made a bad mistake with this last night, but just fixed it. It's now correct for an anemometer that gives 1Hz at 2.5mph.
It's almost too easy
The link you posted was for a device with a reed sensor and 1 ppr. The original link posted by Erica1989 was for a Hall sensor model with multiple pulses, but there was no detail.
I wandered around the inspeed website this morning, and found another link to that model which shows 8ppr and .31mph per Hz. http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-MultiPulse-Sensor-V2-8Pulse.htm
Erica1989 an uncommented line like this which uses "magic numbers" is very poor programming practice
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
Anyone trying to help you will need to know where the 2.5 and 0.447 come from. We're \may be smart enough to figure out that 1000 is bringing ms to seconds, but other than that I'm lost.
cattledog:
The link you posted was for a device with a reed sensor and 1 ppr. The original link posted by Erica1989 was for a Hall sensor model with multiple pulses, but there was no detail.I wandered around the inspeed website this morning, and found another link to that model which shows 8ppr and .31mph per Hz. http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-MultiPulse-Sensor-V2-8Pulse.htm
Erica1989 an uncommented line like this which uses "magic numbers" is very poor programming practice
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);Anyone trying to help you will need to know where the 2.5 and 0.447 come from. We're \may be smart enough to figure out that 1000 is bringing ms to seconds, but other than that I'm lost.
The wind sensor link is as follows. Its based on Hall Sensor. I do not know where did those numbers
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
came from. I just copied the code and tried to run it and see the results
http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-Hall-Sensor-V2Hall.htm
The sensor has only one output.
Hi,
I believe I can explain the numbers.
First some details....
1 mile =1609.344 metres
1 hour=3600 secs
So 1 mph= 1609.344/3600 = 0.44704 m/s (0.447 is close enough).
Next
the device output is 0.31 mph/Hz and provides 8 ppr.
So 1 rev/s= 8p/s. Duration is the time for one revolution.
1 Rev/s = 0.31 * 8 = 2.48 mph ( 2.5 is close enough).
The 1000 is a conversion from milliseconds to seconds.
It all seems to fit.
G
Sent using binary technology-either it works or it doesn't.
Zardof:
Hi,
I believe I can explain the numbers.
First some details....1 mile =1609.344 metres
1 hour=3600 secs
So 1 mph= 1609.344/3600 = 0.44704 m/s (0.447 is close enough).
Next
the device output is 0.31 mph/Hz and provides 8 ppr.So 1 rev/s= 8p/s. Duration is the time for one revolution.
1 Rev/s = 0.31 * 8 = 2.48 mph ( 2.5 is close enough).
The 1000 is a conversion from milliseconds to seconds.
It all seems to fit.
G
Thanks for the calculation. But the sensor, I am using outputs 1Hz pulse at 2.5mph wind. And it has just output line that needs to be pulled by a pull up resistor. The link to the sensor is as follows but you are saying that the calculation is done for 8 pulses per revolution. But the sensor that I am using produces one pulse per revolution. So, this formula is wrong for my sensor measurement ??
http://www.shop.inspeed.com/Vortex-II-Wind-Sensor-with-Hall-Sensor-V2Hall.htm
Sent using binary technology-either it works or it doesn't.
OK, first I corrected my original formula. It was very wrong.
(Sorry Erica, I was way too tired last night.
)
(That's what happens when I try to do maths at 2:30am.)
I remembered that in your other thread, @Erica1989, you said that the anemometer that you're using had an output of 1 pulse per rotation for 1 Hz at 2.5mph, so they're the figures I worked from.
The real formula for an anemometer that gives an output of 1Hz at 2.5mph:-
mph = 2500/duration (Duration in mS)
If it was actually a Vortex II, with an output of 1Hz per .31mph, the formula would be:-
mph = 310/duration (Duration in mS)
So Erica, since you said you have a Vortex II in the first post of this thread, are you really sure that the one you're using truly has an output of 1Hz at 2.5mph?
Either way, just use whichever of the above formulae applies.
And again, sorry for my mistake last night.
OldSteve:
OK, first I corrected my original formula. It was very wrong.
(Sorry Erica, I was way too tired last night.)
(That's what happens when I try to do maths at 2:30am.)I remembered that in your other thread, @Erica1989, you said that the anemometer that you're using had an output of 1 pulse per rotation for 1 Hz at 2.5mph, so they're the figures I worked from.
The real formula for an anemometer that gives an output of 1Hz at 2.5mph:-
mph = 2500/duration (Duration in mS)
If it was actually a Vortex II, with an output of 1Hz per .31mph, the formula would be:-
mph = 310/duration (Duration in mS)So Erica, since you said you have a Vortex II in the first post of this thread, are you really sure that the one you're using truly has an output of 1Hz at 2.5mph?
Either way, just use whichever of the above formulae applies.
And again, sorry for my mistake last night.
Hi,
The sensor's spec. sheet says that it generates 1 pulse per second at 2.5mph.
Now, does the following code good for this kind of application. How can I effectively handle high number of pulses at higher revolutions. The program receives external interrupt on one of its external digital I/O lines, how much delay do I need to make a good reading?
float windspeed; // wind speed
unsigned long start, duration;
int updated = 0; // <<<<-------- flag
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT); //reads the input from pin 2
attachInterrupt( 0, wspeed, RISING );
start=millis();
delay(20);
}
void wspeed()
{
duration = millis() - start;
start = millis();
if ( duration > 20 )
updated = 1;
}
void loop()
{
if (updated == 1)
{
Serial.print (" duration of the one turn ( msec ) : ");
Serial.println ( duration );
Serial.print ("windspeed : ");
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
Serial.print (windspeed);
Serial.println (" m/s");
delay(500);
updated = 0; // <<<<<---- reset a flag, so it woudn't print "old data".
}
else if (updated ==0)
Serial.print (" Not ready");
Serial.print("\n");
}
Erica1989:
Hi,
The sensor's spec. sheet says that it generates 1 pulse per second at 2.5mph.
Then as mentioned, this formula will give you miles per hour instead of metres per second: mph = 2500/duration (duration in mS)
Now, does the following code good for this kind of application.
I can't help feeling that we're wasting our time. Even after being told that any variables modified within your ISR must be declared as volatile, you haven't bothered to do so.
So once again, this:-
unsigned long start, duration;
should look like this:-
volatile unsigned long start, duration;
How can I effectively handle high number of pulses at higher revolutions.
Getting rid of the errors would be a good start. There's no reason that your Arduino shouldn't handle the speeds that you want. The duration is 1000mS at 2.5mph, 100mS at 25mph, 25mS at 100mph. All easy for an Arduino.
The program receives external interrupt on one of its external digital I/O lines, how much delay do I need to make a good reading?
Which delay? Do you mean the 20mS here?:-
if(duration > 20)
updated = 1;
Why do you want that 20mS between valid readings? (Not that you're getting it anyway, because you never actually set 'duration' back to 0. 'duration' is always above 20, unless the wind speed is extra-high and the duration drops below 20mS.)
Even if you were getting 20mS between valid readings, it's meaningless anyway, since you have 'delay(500)' in 'loop()'. You should re-arrange your code and completely stop using 'delay()' anyway. You already know how millis()-based timing works. Either way, the interrupt will be called and 'duration' will be updated every revolution.
I don't see any good reason for the 20mS delay in 'setup()', either.
(That doesn't mean there isn't one, but I can't see it.)
Is this the pin that the anemometer is connected to? :-
pinMode(2, INPUT); //reads the input from pin 2
If so, perhaps this should also be set to pin 2?:-
attachInterrupt(0, wspeed, RISING);
If you wanted, you could also rewrite this:-
windspeed = ( 2.5 * 1000.0 / (float) duration )*(0.447);
to this:-
windspeed = (2500.0 / (float)duration) * 0.447;
or possibly even:-
windspeed = 1117.5 / (float)duration
although I guess it doesn't really matter much if you'll be changing to mph instead of metres per second for the final version.
I'm not sure if I explained everything as well as I could have, but you get the idea. I'm busy on my project right now, and preoccupied again.