user904: I have wind speed sensor that can measure max speed upto 30 m/s with analog out put 0-5v. I have simple code calling from the loop. When I put the wind speed average code, the web server is not working and it just hangs. If I comment out web server it's working fine. Let me know What makes my web server hang or not get connected. Is there any way I can change average taking code?
Working code should like below:
if wind speed exceed 30 m/s 
   mode =stow
else 
   mode =track

My code. And how can write average of windload of day to SDcard
#include"wind.h"
#include"mode.h"

float sampleAverage(void)
{
  float accumulator = 0;
  for (int i = 0; i < SAMPLE_COUNT; i++)
  {
    accumulator += sample[i];
  }
  return accumulator / SAMPLE_COUNT;
}

void Wind_calc()
{

  static unsigned long lastSampleTime = 0;
  unsigned long currentTime = millis();

  // check if time for new reading
  if (currentTime - lastSampleTime >= SAMPLE_RATE)
  {
    lastSampleTime = currentTime;
    int sensorValue = analogRead(SENSOR_PIN);
    float voltage = sensorValue * (5.0 / 1023.0);
    /* Serial.print("voltage: ");
     Serial.println(voltage);*/
    // add the newest reading at the oldest pointer
    sample[sampleIndex] = voltage;
    // advance to next index which is now oldest
    sampleIndex++;
    // check for and handle rollover
    if (sampleIndex == SAMPLE_COUNT)
    {
      sampleIndex = 0;
    }
    // the sample array now contains the last ten readings
    // sampleIndex now points to the oldest reading
    // it will be replaced with the newest next time 

    float average = sampleAverage();
    /*Serial.print("average:");
     Serial.println(average);*/
    Wind_Speed = (6 * average);
    Wind_Kmph = 3.6 * Wind_Speed;
    /*    Serial.print("Wind_Speed:");
     Serial.print(Wind_Speed);
     Serial.println("m/s");

     Serial.print("Wind_Exceed_count:");Serial.println(Wind_Exceed_count);Serial.println(".................");
     Serial.print("Wind_Kmph:");
     Serial.print(Wind_Kmph);
     Serial.println("KMPH");
     */
    if((Wind_Speed>4.0)&&(Stow_flag==0))
    {
      Wind_Exceed_count=Wind_Exceed_count+1;

      //Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
      if(Wind_Exceed_count<5)
      {
        Stow_flag=0;
      }
      else
      {
        Stow_flag=1; 
        MODE=STOW;
      }

    }
    else
    {
      Redo_Wind_calc();
    }


  } 

}


void Redo_Wind_calc()
{
  //  Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
  if(Wind_Speed>4.0 &&Stow_flag==1)
  {
    Wind_Exceed_count=Wind_Exceed_count+1;
    if(Wind_Exceed_count<=10)
    {
      MODE=STOW;    
    }
    else
    {
      MODE=TRACK;
      Wind_Exceed_count=0;
      Stow_flag=0;
    }

  }
}


void loop()
{
 Wind_calc();
webcontrol();
}


void webcontrol()
{

//Web control function are defined here

}


user1113: What arduino board is being used? I find that some webserver code takes up a lot of the SRAM and in an UNO this leaves very little space for other code.
To save SRAM use the F macro on all the Serial.print statements that have quoted text. i.e:
Serial.print("Some text you want output");

This takes up SRAM when running. 1 byte per letter and space.
Serial.print(F("Some text you want output"));

This takes up no SRAM as it is stored in program space and is makes a big difference.
Search for a freeRam() and use that in debugging your sketch to see how much free space you have.
Relevant question: What can I do if I run out of Flash memory or SRAM?

904: <p>I have wind speed sensor that can measure max speed upto 30 m/s with analog out put 0-5v. I have simple code calling from the loop. When I put the wind speed average code, the web server is not working and it just hangs. If I comment out web server it's working fine. Let me know What makes my web server hang or not get connected. Is there any way I can change average taking code?</p>

<p><strong>Working code should like below:</strong></p>

<pre><code>if wind speed exceed 30 m/s 
   mode =stow
else 
   mode =track
</code></pre>

<p>My code. And how can write average of windload of day to SDcard</p>

<pre><code>#include"wind.h"
#include"mode.h"

float sampleAverage(void)
{
  float accumulator = 0;
  for (int i = 0; i &lt; SAMPLE_COUNT; i++)
  {
    accumulator += sample[i];
  }
  return accumulator / SAMPLE_COUNT;
}

void Wind_calc()
{

  static unsigned long lastSampleTime = 0;
  unsigned long currentTime = millis();

  // check if time for new reading
  if (currentTime - lastSampleTime &gt;= SAMPLE_RATE)
  {
    lastSampleTime = currentTime;
    int sensorValue = analogRead(SENSOR_PIN);
    float voltage = sensorValue * (5.0 / 1023.0);
    /* Serial.print("voltage: ");
     Serial.println(voltage);*/
    // add the newest reading at the oldest pointer
    sample[sampleIndex] = voltage;
    // advance to next index which is now oldest
    sampleIndex++;
    // check for and handle rollover
    if (sampleIndex == SAMPLE_COUNT)
    {
      sampleIndex = 0;
    }
    // the sample array now contains the last ten readings
    // sampleIndex now points to the oldest reading
    // it will be replaced with the newest next time 

    float average = sampleAverage();
    /*Serial.print("average:");
     Serial.println(average);*/
    Wind_Speed = (6 * average);
    Wind_Kmph = 3.6 * Wind_Speed;
    /*    Serial.print("Wind_Speed:");
     Serial.print(Wind_Speed);
     Serial.println("m/s");

     Serial.print("Wind_Exceed_count:");Serial.println(Wind_Exceed_count);Serial.println(".................");
     Serial.print("Wind_Kmph:");
     Serial.print(Wind_Kmph);
     Serial.println("KMPH");
     */
    if((Wind_Speed&gt;4.0)&amp;&amp;(Stow_flag==0))
    {
      Wind_Exceed_count=Wind_Exceed_count+1;

      //Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
      if(Wind_Exceed_count&lt;5)
      {
        Stow_flag=0;
      }
      else
      {
        Stow_flag=1; 
        MODE=STOW;
      }

    }
    else
    {
      Redo_Wind_calc();
    }


  } 

}


void Redo_Wind_calc()
{
  //  Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
  if(Wind_Speed&gt;4.0 &amp;&amp;Stow_flag==1)
  {
    Wind_Exceed_count=Wind_Exceed_count+1;
    if(Wind_Exceed_count&lt;=10)
    {
      MODE=STOW;    
    }
    else
    {
      MODE=TRACK;
      Wind_Exceed_count=0;
      Stow_flag=0;
    }

  }
}


void loop()
{
 Wind_calc();
webcontrol();
}


void webcontrol()
{

//Web control function are defined here

}
</code></pre>
 1113: <p>What arduino board is being used? I find that some webserver code takes up a lot of the SRAM and in an UNO this leaves very little space for other code.</p>

<p>To save SRAM use the F macro on all the Serial.print statements that have quoted text. i.e:</p>

<pre><code>Serial.print("Some text you want output");
</code></pre>

<p>This takes up SRAM when running. 1 byte per letter and space.</p>

<pre><code>Serial.print(F("Some text you want output"));
</code></pre>

<p>This takes up no SRAM as it is stored in program space and is makes a big difference.</p>

<p>Search for a <code>freeRam()</code> and use that in debugging your sketch to see how much free space you have.</p>

<p>Relevant question: <a href="https://arduino.stackexchange.com/questions/221/what-can-i-do-if-i-run-out-of-flash-memory-or-sram">What can I do if I run out of Flash memory or SRAM?</a></p>
