Go Down

Topic: Arduino Pro and Anemometer (Reading Pulse Times) (Read 3 times) previous topic - next topic

DynamiK

I am using a Wind Vaned Anemometer to find the wind speed and direction. The system uses two sets of reed switches (one used for speed and one used for direction).

I am trying to print out the data to the serial monitor to confirm the data I am reading in, but am receiving nothing.

Can someone offer my some advice? I checked my syntax and I'm not sure if it is the way that it is being written or if it has to do with my timing.

When I hook up my system to the oscilloscope this is the reading that I get.


What I'm trying to do is calculate the time difference between the yellow pulses to figure out my RPM. And use the Time difference between the yellow and blue pulses to calculate phase shift to give me direction.

I referenced this other thread to give me what I have now: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1265052228

Quote

//////////////////////////////////////////////////////////
//    Declaration of Variables   //
//////////////////////////////////////////////////////////
           
int analogSpeed = 0;             //Speed bus connected to analog pin 0
int analogDirection = 1;          //Direction bus connected to analog pin 1
unsigned long Speedvalue =  0;
unsigned long Directionvalue = 0;

// Variables for time
unsigned long SpeedDuration;
unsigned long DirectionDuration;
unsigned long SpeedTimePrevious;
unsigned long DirectionTimePrevious;
unsigned long DirectionTimePrevious1;
unsigned long DirectionTimePeriod;
unsigned long TimeDifference;
unsigned long Frequency;

// Variables for counting
volatile byte count;

void setup()
{
pinMode (analogSpeed, INPUT);
pinMode (analogDirection, INPUT);
Serial.begin(9600);          // Setup serial with baud rate
attachInterrupt(0, arduino_anemometer, RISING);
count = 0;
SpeedDuration = 0;
DirectionDuration = 0;
SpeedTimePrevious = 0;
DirectionTimePrevious = 0;
DirectionTimePrevious1 = 0;

TimeDifference = 0;
}

void loop()
{
///////////////////////////////////////////////////////////////////////////////////////////
// It takes about 100 microseconds to read an analog input    //
// Max reading rate is 10,000 times a second          //
/////////////////////////////////////////////////////////////////////////////////////////

//Do I want digital or analog read??

Speedvalue = analogRead(analogSpeed);       // Read the input pin at 0
Directionvalue = analogRead(analogDirection);    // Read the input pin at 1

if (count >= 1)
{
   //Calculating Speed Duration
SpeedDuration = (millis() - SpeedTimePrevious);
SpeedTimePrevious = millis();


if (SpeedTimePrevious  >  DirectionTimePrevious)
{
DirectionDuration = (millis() - DirectionTimePrevious);
DirectionTimePrevious = millis();
DirectionTimePeriod = (DirectionTimePrevious - DirectionTimePrevious1);
}

// Calculates Frequency between DIRECTION signals
DirectionTimePrevious1 = DirectionTimePrevious;
Frequency = 1/DirectionTimePeriod;


// Calculates time difference between SPEED and DIRECTION signals
if (DirectionTimePrevious != 0 )   // Ensures that Direction must occur second
{
TimeDifference = (SpeedTimePrevious - DirectionTimePrevious);
}

count = 0;

//////////////////////////////////
//   VALUES   //
/////////////////////////////////
Speedvalue = (1492/SpeedDuration);      // Finds speed of cup rotation in
Directionvalue = 360*Frequency*TimeDifference; //Finds Angle of Wind Vein

/////////////////////////////////////////////////////////////////////////////
//   Printing SPEED, DIRECTION, TIME   //
/////////////////////////////////////////////////////////////////////////////
Serial.print("Speed: ");
Serial.println(Speedvalue, DEC);
//delay(1000);
Serial.print("Direction: ");
Serial.println(Directionvalue, DEC);
//delay(1000);
Serial.print("Time: ");
Serial.println(millis());
//delay(1000);

}

}

void arduino_anemometer()
{
count++;


PaulS

Quote
I am trying to print out the data to the serial monitor to confirm the data I am reading in, but am receiving nothing.

You are only printing a value when count is greater than 0. The count variable only gets incremented in the interrupt function. That you get nothing in the serial monitor implies that the interrupt handler is not being called, which implies that the Arduino is not receiving any signal on digital pin 2. What is connected to that pin?

robtillaart

from your code:
Quote
//Do I want digital or analog read??


As I see the pulses in the scope I would go for a digital read as it seems a nice square wave.

What is the voltage measured? You might need to boost it to get a decent level.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

DynamiK

Quote
You are only printing a value when count is greater than 0.

I took my printing out of the IF statement for now, but I may want to put it back there once I get the reading for the interrupt correct.

Quote
which implies that the Arduino is not receiving any signal on digital pin 2. What is connected to that pin?

You are right, I didn't connect anything to Digital Pin 2. I misread the how the interrupt function worked. I put my two inputs into Analog 0 and Analog 1.

I wanted to be able to tell when my analog signal rises so I can find the difference in time from when the signals rise relative to one another, and use that time to calculate speed and direction using RPM's and Phase Shift.

Since my signals are close to squares, could I send them through the digital pins (2,3). How would I handle the interrupt if now I have two different signals that I will need to compare?

Quote
As I see the pulses in the scope I would go for a digital read as it seems a nice square wave.

What is the voltage measured? You might need to boost it to get a decent level.

Input voltage is being regulated to 5 V, from a DC power Supply that is simulating a solar panel voltage for now.

scruss

I think you might want to look at some of the tachometer examples on this board, like Counting PulseIn.

I know a bit about anemometry and wind resource assessment. Are you sure your wind vane uses a reed switch? Don't think I've ever seen one of those, unless it uses several switches to indicate wind sectors.

Typical wind vanes are either:

  • linear potentiometer -- linear output from 2° to 358°. Really nice ones are linear from -90° to 450° to help with direction trending.

  • Gray code -- has several ttl outputs which generate a bitmap from which the wind sector can be deduced.



Reed switch anemometers are probably the easiest to read, but are quite low resolution. They work well with long cables. Other types are linear (voltage or current loop), low voltage AC (with frequency proportional to wind speed) and square wave (usually generated by a photochopper).

Since most wind data loggers (even the really expensive ones used for utility-grade work) are many times less powerful than an Arduino, I've been meaning to develop a decent logger sketch.

Go Up