I heart Processing

Investigating hooking up a heartbeat monitor to Processing

Ingredients

Method

  1. Connect your PulseSensor to the Arduino. The physical set up looks like this (using the helpful PulseSensor getting started guide):
  2. Connect your Arduino to your computer. Run some listening code in Processing on your computer – download the code and paste it into a sketch. Essentially, we use the serial package to set up a Serial object, which triggers serial events every time there’s enough data for us to do something with. The data coming from the PulseSensor is a bit of text (a String) which either stars with an S, B or Q followed by a number, so here’s how we grab that number out of it:
    /* a special function which captures "serial events" - i.e. data sent from the serial port */
    void serialEvent(Serial port)
    { 
       String inData = port.readStringUntil('\n');
       inData = trim(inData);   // cut off white space 
       
       println(inData); // debug! see what you've got
       
       if (inData.charAt(0) == 'S') //leading "S" for sensor data
       {          
         inData = inData.substring(1); // cut off the leading 'S' 
         Sensor = int(inData);         // convert the string to usable int
       }
       if (inData.charAt(0) == 'B') // leading "B" for BPM data
       {          
         inData = inData.substring(1); // cut off the leading 'B'
         BPM = int(inData);            // convert the string to usable int
         // set beat flag to advance heart rate graph
         beat = true;
       }
     if (inData.charAt(0) == 'Q') // leading "Q" for IBI data
     {            
         inData = inData.substring(1); // cut off the leading 'Q'
         IBI = int(inData);            // convert the string to usable int
     }
    }
  • Look at the code’s
    keyPressed()

    method – you can switch between the two modes defined in

    draw()

    by pressing either 1 or 2!

  • Screenshots from the code (not very exciting so please do experiment with your own patterns!

Examples of doing things with heart rates:

Examples of doing things with data from physical sensors:

Places to buy kit

 

Bookmark the permalink.

Comments are closed