0

I have a question .. Please help me I don't know how Arduino can read the peak value of the sensor signal. The value I want is in the ADC value .. What I want is ... for 5 seconds there will be 1 average value from the highest peak value of the sensor, and the ADC value. I will use pin A0, but I don't know how to code the program that I want. Please help me What is the code?

0

See if I understand this correctly: For a given time period you want to find the peak.

void setup()
{
  unsigned long int cur_time = 0 ;
  unsigned long int time_elapsed = 0;
  int peaks[20]; // say you want to find 20 peaks , 1 peak for data arriving between 5 secs
  int time_period = 5000;  
  int data = 0; 
  int mx=0;
}

void loop()
{
   for(int i = 0 ; i<20;i++)
   { 
      cur_time = millis();
      while(cur_time - time_elapsed <=time_period)
      { 
             if(mx==0)
              { mx = analogRead(A0); } 
              else:
               {  data = analogread(A0);
                  mx = max(data , mx);  
               }
              cur_time = millis();
        } 
         time_elapsed = cur_time;
         peaks[i] = mx;
         mx = 0; 
        }
  }  

Hope this helps!!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.