-
Notifications
You must be signed in to change notification settings - Fork 207
Description
I have a problem similar to at least two others that have been reported (but I couldn't find a solution so far). The bpm output of the sensor sometimes goes up to unrealistic values (~150) while the times series of the heartbeat appears to be transmitted truthfully. The problem becomes evident already when I look at the 'raw' output in the serial monitor (so its not my later processing of that output). Even without being attached to a finger the bpm shoots up once in a while, while the heart beat time series remains quite constant and certainly below my provided threshold.
I'm using an Arduino Uno Rev 3. To the same board I have attached a GSR and an EMG sensor (which is handled in the code below, too). I use version 1.2.3 of the PulseSensor Playground library (since later versions gave me compiler errors).
I know that other people had the same problem too, but in one case the sensor was fake, in the other I think no solution was found. I'm using the sensor to teach medical students how mental states influence physiological responses by visualizing several physiological parameters with matlab while they perform mentally stressful tasks. I and they would be really grateful if there was a solution to the problem.
Find attached a photo of my sensor and my code.
Thanks!
Jens
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
const int OUTPUT_TYPE = SERIAL_PLOTTER;
const int PIN_INPUT = A0;
const int PIN_BLINK = 13; // Pin 13 is the on-board LED
const int THRESHOLD = 720; // tried this with values up to 950
int h1;
int h2;
int h3;
int g;
int m;
PulseSensorPlayground pulseSensor; // all the PulseSensor Playground functions.
void setup() {
Serial.begin(115200);
// Configure the PulseSensor manager.
pulseSensor.analogInput(PIN_INPUT);
pulseSensor.blinkOnPulse(PIN_BLINK);
pulseSensor.setSerial(Serial);
pulseSensor.setOutputType(OUTPUT_TYPE);
pulseSensor.setThreshold(THRESHOLD);
// Now that everything is ready, start reading the PulseSensor signal.
if (!pulseSensor.begin()) {
/*
If your Sketch hangs here, try ProcessEverySample.ino,
which doesn't use interrupts.
*/
for (;;) {
// Flash the led to show things didn't work.
digitalWrite(PIN_BLINK, LOW);
delay(50);
digitalWrite(PIN_BLINK, HIGH);
delay(50);
}
}
}
void loop() {
delay(20); // was 20
// Get the sensor data
h1 = pulseSensor.getLatestSample();
h2 = pulseSensor.getBeatsPerMinute();
h3 = pulseSensor.getInterBeatIntervalMs();
g = analogRead(A1);
m = analogRead(A2);
// Send data to serial port
Serial.print(h1); // Full heart time series
Serial.print(F(","));
Serial.print(h2); // BPM
Serial.print(F(","));
Serial.print(h3); // IBI
Serial.print(F(","));
Serial.print(g); // GSR
Serial.print(F(","));
Serial.print(m); // Muscle
Serial.println();
if (pulseSensor.sawStartOfBeat()) {
pulseSensor.outputBeat();
}
}
