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
//////////////////////////////////////////////////////////
// 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 1if (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 = 360FrequencyTimeDifference; //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++;
}