Using an Arduino Nano to sense wind speed

I tried using a Raspberry Pi to count the number of times the Wind Speed Anemometer revolved, but the Pi was unable to keep up.

So I used an Arduino Nano to do the counting.  The Raspberry Pi then looks for the output from the Arduino Nano


volatile byte count;

unsigned int loopcount;

unsigned int maxofcount;
unsigned int araysum;

unsigned int duration;
unsigned long tenseconds;
unsigned long sixtyseconds;

int countarray[6];

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  attachInterrupt(0, arduino_anemometer, RISING);
  
  tenseconds = millis() + 10000;
  sixtyseconds = millis() + 60000;
  
  //countarray[]= {0,0,0,0,0,0};
  
  loopcount = 0;
  maxofcount = 0;
  Serial.print("Startup\n");
  //printwait();
  count = 0;
}

void loop()
{
  if (millis() > tenseconds) 
    {
      countarray[loopcount] = count;
      loopcount++;
      if (loopcount > 5)
        {
            maxofcount = getIndexOfMaximumValue(countarray, 6); 
            araysum = getSumofArray(countarray, 6);
            Serial.print("Current Count#");
            Serial.print(araysum,DEC);
            Serial.print("#Burst#");
            Serial.print(maxofcount,DEC); 
            Serial.print("#\r");
            
            loopcount = 0;
            sixtyseconds = millis() + 60000;
        }

      //printwait();
      tenseconds = millis() + 10000; 
      count = 0;
      //Serial.print("\n");
    }
  else
     {
        if(millis() < (tenseconds - 20000))
          {
            tenseconds = millis() + 10000;
          }
     } 
}

void arduino_anemometer()
{
  count++;
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
}


void printwait()
  {
      Serial.print("\n");
      Serial.print("                                   Current time - ");
      Serial.print(millis());
      Serial.print("      tenseconds = ");
      Serial.print(tenseconds);
      Serial.print("      sixtyseconds = ");
      Serial.print(sixtyseconds);
  }
  

int getIndexOfMaximumValue(int* array, int size)
  {
    int maxvalue = 0;
    for (int i=0; i<size; i++)
      {
        //Serial.print("\n");
        //Serial.print("              Array Number ");
        //Serial.print(i);
        //Serial.print("  Array value ");
        //Serial.print(array[i]);
        //Serial.print("  Max value ");
        //Serial.print(maxvalue);
  
        if (maxvalue < array[i])
          {
            maxvalue = array[i];
          }
    }
    return maxvalue;
  }

int getSumofArray(int* array, int size)
  {
    int sumofarray = 0;
    for (int i=0; i<size; i++)
      {
        sumofarray = sumofarray + array[i];
      }
    return sumofarray;
  }

5PCS USB CH340G Nano V30 16M 5V ATmega328P Micro Controller Board For Arduino
5PCS USB CH340G Nano V30 16M 5V ATmega328P Micro Controller Board For Arduino $18.85
End Date: Thursday Jun-21-2018 15:35:33 PDT
Buy It Now for only: $18.85
MINI USB Nano V30 ATmega328P CH340G 5V 16M Micro controller board Arduino
MINI USB Nano V30 ATmega328P CH340G 5V 16M Micro controller board Arduino $5.95
End Date: Friday Jul-6-2018 22:22:50 PDT
Buy It Now for only: $5.95
Arduino Nano V30 CH340G Micro Controller ATmega328 16M 5V USA Ships Today Kit
Arduino Nano V30 CH340G Micro Controller ATmega328 16M 5V USA Ships Today Kit $4.99
End Date: Tuesday Jul-10-2018 7:09:38 PDT
Buy It Now for only: $4.99
Zyltech Mini USB Nano V30 ATmega328 CH340G Board for Arduino
Zyltech Mini USB Nano V30 ATmega328 CH340G Board for Arduino $3.59
End Date: Saturday Jul-21-2018 8:47:34 PDT
Buy It Now for only: $3.59
Mini USB Nano V30 ATmega328 16M 5V Micro controller CH340G board For Arduino
Mini USB Nano V30 ATmega328 16M 5V Micro controller CH340G board For Arduino $3.45
End Date: Friday Jun-29-2018 16:52:28 PDT
Buy It Now for only: $3.45
V30 ATmega328 USB Nano Micro controller For Arduino CH340G Board
V30 ATmega328 USB Nano Micro controller For Arduino CH340G Board $3.17
End Date: Sunday Jul-1-2018 16:02:59 PDT
Buy It Now for only: $3.17
3X Fully Assembled Arduino Nano 30 ATmega328P Micro Controller
3X Fully Assembled Arduino Nano 30 ATmega328P Micro Controller $12.99
End Date: Monday Jul-9-2018 16:56:47 PDT
Buy It Now for only: $12.99
USB Nano V30 ATmega328 16M 5V Micro controller CH340G board For Arduino
USB Nano V30 ATmega328 16M 5V Micro controller CH340G board For Arduino $2.80
End Date: Saturday Jun-30-2018 17:16:05 PDT
Buy It Now for only: $2.80
Arduino Nano V30 CH340G Micro Controller ATmega328 16M 5V USA Ships Today Assm
Arduino Nano V30 CH340G Micro Controller ATmega328 16M 5V USA Ships Today Assm $5.94
End Date: Saturday Jul-7-2018 21:37:02 PDT
Buy It Now for only: $5.94
Rapid Prototyping LED Breadboard for Arduino UNO MEGA2560 NANO PRO MCU LoL Shiel
Rapid Prototyping LED Breadboard for Arduino UNO MEGA2560 NANO PRO MCU LoL Shiel $0.99
End Date: Friday Jun-29-2018 1:56:25 PDT
Buy It Now for only: $0.99

« Previous12345...910

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>