PulseSensor_Amped_Arduino icon indicating copy to clipboard operation
PulseSensor_Amped_Arduino copied to clipboard

Calculate the average of pulse

Open shadowwalkersteam opened this issue 8 years ago • 7 comments

How i can calculate the average of pulse sensor? I have tried this code but it didn't worked and even the values didn't showed up in serial monitor and in processing. `
for(int i=0; i<64; i++)

{ // Average over 16 measurements Signal += analogRead(pulsePin); }

Signal= Signal/64; `

shadowwalkersteam avatar Aug 31 '17 07:08 shadowwalkersteam

I did this in interrupt.ino where it is reading from A0

shadowwalkersteam avatar Aug 31 '17 07:08 shadowwalkersteam

Interesting. Well, you are taking 64 readings of the ADC. It takes Arduino (ATmega) about 100uS to do an Analog read. Your loop takes ~6.4mS to complete. There's your problem right there. You need to reduce the number of samples you are averaging. Our Arduino Code interrupts to sample every 2mS. You need to limit the amount of samples you take to >20.

Also, are you resetting the Signal variable to 0? If not, you are just adding and adding to it.

joelSensor avatar Aug 31 '17 14:08 joelSensor

Ok i'll try that... I'm using arduino pro mini and i'm using timer1 as it mentioned that is used 9 and 11 pin and my 9th and 11th pin are not free will it cause a problem or should i use timer2 for pro mini 5v version

shadowwalkersteam avatar Aug 31 '17 18:08 shadowwalkersteam

which is more stable? and what is the threshold value so that i could minimize the noise

shadowwalkersteam avatar Aug 31 '17 18:08 shadowwalkersteam

The only thing that the Timer selection does to those pins is not allow you to use PWM. Timer 2 breaks PWM on pins 3 and 11 Timer 1 breaks PWM on pins 9 and 10 You can use those pins for other digital things.

As for the threshold, you will have to play around with the default value of the thresh varialbe in the interrupts

biomurph avatar Aug 31 '17 20:08 biomurph

Okay.. please suggest me which timer i should use for pro mini 5v 16mhz ?

shadowwalkersteam avatar Sep 01 '17 04:09 shadowwalkersteam

You could use either one. Depends on if you want to use PWM on any of the pins. Simple.

biomurph avatar Sep 01 '17 13:09 biomurph