Introduction: Customizing PulseSensor Visualizer to Trigger Event (Anti-Productivity Monitor)

In this instructable you will be learning how to modify the PulseSensor Visualizer Program to trigger an event in a web browser. I am calling this project the Anti Productivity Monitor because while we have many tools that help us monitor our vitals, our schedules, and our food intake, there isn't much out there that reminds us to take a few minutes out of our busy days to slow down and breathe.

Step 1: What You'll Need

- PulseSensor heart-rate sensor kit, which includes:

  • Soft braided-wire ribbon cable
  • Ear clip (sized to the sensor)
  • Velcro Finger Strap

- Arduino Uno

- Arduino IDE, for uploading code to your Arduino

- Processing App, for BPM visualizer

- PulseSensor Playground Library (For Arduino)

- PulseSensor Amped Processing Visualizer (For Processing)

Step 2: Preparing the Plugging PulseSensor for Arduino

Because the sensor is an exposed circuit board, you need to find a way to keep any oil or sweat from coming in contact with those components. You can use hot glue or nail polish. DO NOT cover the white side or the sensor with any opaque material, this render your sensor useless.

Plug in the wires to the corresponding ports:

5v - RED CABLE

Ground - BLACK CABLE

Analog 0 (A0) - Purple Cable

Step 3: Arduino Code Install and Upload

Once the Arduino AND Processing software is downloaded and installed, Load the Playground Library into the Arduino library. In the Arduino app, go to Sketch > Include Library > Manage Library. Search for PulseSensor and install the library.

Next open the example code by going to > Examples > PulseSensor Playground. For our purposes, we will be using PulseSensor_BPM. This example code ultimately is designed to send serial data to Processing. Before we can upload the sketch to our Arduino, we must change a line of code so the arduino data is sent to processing. The variable output_type by default is set to SERIAL_PLOTTER. This must be changed to PROCESSING_VISUALIZER.

Step 4: Processing Code Install and Upload

After downloading the PulseSensor Amped Visualizer file and unzip it. Find the file called "PulseSensor_Amped_Processing_150" and place it in your Documents > Processing folder.

Now open Processing and go to file > sketch and click on PulseSensorAmped_Processing_Visualizer.

Step 5: Test

When you click run in Processing, a window will open asking what serial port you would like to use. Usually the Arduino port is at the top of the list. Select the port, and place the sensor on anywhere on your body you can normally feel your pulse. You should see regular readings of your BPM!

Step 6: Customize the Visualizer Program

Once you have the program successfully running, there are many changes you can make to customize the experience. However, be wary of what code you add or manipulate. It could break the program!

One fun small change you can do is change the text() function in line 87 to read anything you want. It originally says PulseSensor Amped Visualizer. I changed mine to say Anti Productivity Monitor.

One major change I made I placed under the void drawheart() function and before the void listAvailablePorts() function. Here is the code:

Declare the variable openWindow before the end of the draw loop like so:

openWindow();

} //end of draw loop

The function is placed under the void drawheart() function and before the void listAvailablePorts() function.

void openWindow () {

while (BMP >= 120) {

link("link of your choice");

}

This code constantly checks the readings from arduino, and any reading above 120 BPM triggers a youtube video to open in the default browser.

WARNING: Do not run the visualizer until AFTER reading the following problem and solution.

Step 7: Problems

Because the openWindow command looks for BPM values above 120 HUNDREDS of times a second, it could trigger a link to open every time it registers past the threshold. You will see this in the screen shot above. I opened HUNDREDS of new tabs within seconds. This completely froze my computer - I had to restart it! To avoid this issue, insert a delay() command after the link command like this.

void openWindow () {
while (BMP >= 120) {

link("link of your choice");

delay(60000);

}

Time is measured in millis in processing, and 60,000 millis equal one minute.

Step 8: Final Product

Success! When the users BMP reaches past 120 BPM, a link is opened in your browser. The loop will delay for one minute.