Hello, i bought a pulse sensor recently and connected it correctly. It can work and the LED blinks with my heart beat. However, it just work for the first several seconds(BPM=70~90), and then it becomes inaccurate. The BPM reaches to 150-200. what's wrong with it?
My code is download from the pulse sensor websites, i think it should be correct.
Does anyone meet the same problem and know how to solve it ?
Pulse Sensor: Inaccurate detection
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Pulse Sensor: Inaccurate detection
It sounds like you might have an intermittent connection somewhere.
Could you post a photo of your hardware and connections please? 800x600 images usually work best.
Could you post a photo of your hardware and connections please? 800x600 images usually work best.
- jeffpan
- Posts: 3
- Joined: Fri Feb 27, 2015 8:26 pm
Re: Pulse Sensor: Inaccurate detection
the hardware connection is shown below. I have tried both timer0 adn timer1 that is introduced in the pulsesensor.myshopify.com/pages/pulse-sensor-amped-arduino-v1dot1 .adafruit_support_mike wrote:It sounds like you might have an intermittent connection somewhere.
Could you post a photo of your hardware and connections please? 800x600 images usually work best.
Also, i tried to comment/uncomment the ''analogReference(EXTERNAL); ''
The code i use is shown:
Code: Select all
int pulsePin = 10; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 7; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, must be seeded!
volatile boolean Pulse = false; // true when pulse wave is high, false when it's low
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
//Serial.begin(9600);
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
// AND APPLY THAT VOLTAGE TO THE A-REF PIN
analogReference(EXTERNAL);
}
void loop(){
sendDataToProcessing('S', Signal); // send Processing the raw Pulse Sensor data
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse
sendDataToProcessing('B',BPM); // send heart rate with a 'B' prefix
sendDataToProcessing('Q',IBI); // send time between beats with a 'Q' prefix
QS = false; // reset the Quantified Self flag for next time
}
ledFadeToBeat();
delay(20); // take a break
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
void sendDataToProcessing(char symbol, int data ){
Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
Serial.println(data); // the data to send culminating in a carriage return
}
the interrupt code:
Code: Select all
void interruptSetup(){
// Initializes Timer1 or Timer 0 to throw an interrupt every 2mS.
// TCCR1A = 0x00; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
// TCCR1B = 0x0C; // DON'T FORCE COMPARE, 256 PRESCALER
// OCR1A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
// TIMSK1 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER1 AND OCR2A
TCCR0A = 0x02;
TCCR0B = 0x04; // these put the timer into CTC mode and set the prescaler to 256
OCR0A = 0x7C; // timer0 counts to 124, then gets reset to 0
TIMSK0 = 0x02; // enable interrupt on OCR0A match
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}
// THIS IS THE TIMER 2 INTERRUPT SERVICE ROUTINE.
// Timer 2 makes sure that we take a reading every 2 miliseconds
ISR(TIMER0_COMPA_vect){ // triggered when Timer2 counts to 124
cli(); // disable interrupts while we do this
Signal = analogRead(pulsePin); // read the Pulse Sensor
sampleCounter += 2; // keep track of the time in mS with this variable
int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid noise
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Pulse Sensor: Inaccurate detection
A multimeter is too slow to catch the changes an intermittent connection produces.
Try connecting a jumper with alligator clips between pad D10 on the Flora and the solder joint for the purple wire on the veroboard. See if that helps.
Try connecting a jumper with alligator clips between pad D10 on the Flora and the solder joint for the purple wire on the veroboard. See if that helps.
- jeffpan
- Posts: 3
- Joined: Fri Feb 27, 2015 8:26 pm
Re: Pulse Sensor: Inaccurate detection
Yes, I have done that and it still got the same result.adafruit_support_mike wrote:A multimeter is too slow to catch the changes an intermittent connection produces.
Try connecting a jumper with alligator clips between pad D10 on the Flora and the solder joint for the purple wire on the veroboard. See if that helps.
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Pulse Sensor: Inaccurate detection
Try the power and ground connections as well. If that doesn't help, we can get you a replacement.
Please be positive and constructive with your questions and comments.