Hi everyone.
i'm using 2 pulse sensors (the one with a heart shape in it) to measure my BPM both in the same time because each one will be connected to a different place.
the problem is that when i use only one everything is fine, once i add the second one only the first one gives me BPM and the second doesn't detect it.
when i switch places, the second one work and the first one not.
So, my question is (does Arduino nano support 2 interrupt pins at the same time?) i'm using A0 and A7 (tried different combinations) )
/* Getting_BPM_to_Monitor prints the BPM to the Serial Monitor, using the least lines of code and PulseSensor Library.
Tutorial Webpage: https://pulsesensor.com/pages/getting-advanced
--------Use This Sketch To------------------------------------------
1) Displays user's live and changing BPM, Beats Per Minute, in Arduino's native Serial Monitor.
2) Print: "♥ A HeartBeat Happened !" when a beat is detected, live.
2) Learn about using a PulseSensor Library "Object".
4) Blinks LED on PIN 13 with user's Heartbeat.
--------------------------------------------------------------------*/
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
const int OUTPUT_TYPE = SERIAL_PLOTTER;
/*
Number of PulseSensor devices we're reading from.
*/
const int PULSE_SENSOR_COUNT = 2;
// Variables
const int PULSE_INPUT0 = A0;
const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED
const int PULSE_FADE0 = 5;
const int PULSE_INPUT1 = A7;
const int PULSE_BLINK1 = 3;
const int PULSE_FADE1 = 11;
const int THRESHOLD = 525; // Adjust this number to avoid noise when idle
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.
PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
void setup() {
Serial.begin(250000); // For Serial Monitor
// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PULSE_INPUT0, 0);
pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
pulseSensor.fadeOnPulse(PULSE_FADE0, 0);
pulseSensor.analogInput(PULSE_INPUT1, 1);
pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
pulseSensor.fadeOnPulse(PULSE_FADE1, 1);
pulseSensor.setSerial(Serial);
pulseSensor.setOutputType(OUTPUT_TYPE);
pulseSensor.setThreshold(THRESHOLD);
// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
}
}
void loop() {
int BPM1 = pulseSensor.getBeatsPerMinute(0); // Calls function on our pulseSensor object that returns BPM as an "int".
int BPM2 = pulseSensor.getBeatsPerMinute(1); // Calls function on our pulseSensor object that returns BPM as an "int".
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
if (pulseSensor.sawStartOfBeat(i)) {
pulseSensor.outputBeat(i);
if (i == 0)
{
Serial.print("BPM (1): ");
Serial.println(BPM1);
}
else{
Serial.print("BPM (2): ");
Serial.println(BPM2);
}
}
}
delay(20); // considered best practice in a simple sketch.
}