Two (or more) Pulse Sensors

This Tutorial will show you how to connect more than one Pulse Sensor to an Arduino UNO. We are using two Pulse Sensors to keep things simple, but you can have as many Pulse Sensors as you have analog input pins (6 for the Arduino UNO, for example). 

 

Here's a list of the materials you will need:

 

Our Pulse Sensor Arduino code is designed to find the moment of heart beat in the pulse waveform for accurate BPM calculation. Go to the Pulse Sensor Playground README for instructions on installing the Pulse Sensor Playground Library in Arduino. Once you've done that, navigate to

File > Examples > PulseSensor Playground > TwoPulseSensors_On_OneArduino

The fritzing diagram above shows the connections that need to be made. We are attaching one of the Pulse Sensor purple wires to analog pin A0, and the other one to analog pin A1. The LEDs associated with the Pulse Sensor on A0 are shown in YELLOW. Pin 13 is the blink pin and pin 5 is the fade pin. The LEDs associated with the Pulse Sensor on pin A1 are shown in GREEN. Pin 12 is the blink pin, and pin 11 is the fade pin. After you upload the sketch, turn on the Arduino Serial Plotter

Tools > Serial Plotter

Then you should see the two Pulse Sensor waveforms.

 If you want to see all of the BPM info, we made a sketch in Processing that will visualize both pulse waves and print the BPM values. Here's a screenshot of what that looks like

 

Check out the guide here.

Code Walkthrough

Now let's look into how the code is working. In the example, the pin connections are set near the top of the sketch.

const int PIN_INPUT0 = A0;
const int PIN_BLINK0 = 13;
const int PIN_FADE0 = 5;

const int PIN_INPUT1 = A1;
const int PIN_BLINK1 = 12;
const int PIN_FADE1 = 11;

If you want to add more Pulse Sensors, you can declare more pin aliases here.

NOTE: the pin you use for PIN_FADE should be capable of PWM. If not, it won't work!

In order to use more than one Pulse Sensor, we have to create an instance of PulseSensor Playground that says how many we want to use. Near the top of the code, there is a variable declaration:

const int PULSE_SENSOR_COUNT = 2;

You can change that if you have more than 2 Pulse Sensors. Then the library is invoked thusly:

PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);

The next thing we have to do is pass the pins definitions along to the library like this:

pulseSensor.analogInput(PIN_INPUT0, 0);
pulseSensor.blinkOnPulse(PIN_BLINK0, 0);
pulseSensor.fadeOnPulse(PIN_FADE0, 0);

pulseSensor.analogInput(PIN_INPUT1, 1);
pulseSensor.blinkOnPulse(PIN_BLINK1, 1);
pulseSensor.fadeOnPulse(PIN_FADE1, 1);

The second parameter inside those parenthesis tells the Playground how many pulse sensors we're using. If you want to use more than two, you simply need to do the above for as many Pulse Sensors as you're using.

Those are the biggest changes that you need to make when you're using more than one Pulse Sensor. the function outputSample(), which prints the Pulse Sensor signal to the serial port will print all of the Pulse Sensor values in succession. 

When we check to see if there has been a heartbeat, we have to scroll through the Pulse Sensors with a for loop, like this

for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
     if (pulseSensor.sawStartOfBeat(i)) {
          pulseSensor.outputBeat(i);
     }
}

Arduino Compatibility:

 Our Pulse Sensor code is written to use a hardware Timer interrupt on the chip that is the 'brains' of the Arduino. However, the Library does not accommodate all the myriad types of Arduino boards! If you are using an Arduino board that our code does not support we have another example sketch that will work! Just click on 

File > Examples > PulseSensor Playground > TwoPulseSensors_On_OneArduino_Alternative