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?

asked Feb 20, 2020 at 6:03

1 Answer 1

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!!

answered Feb 20, 2020 at 7:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.