Investigating hooking up a heartbeat monitor to Processing
Ingredients
- A heart rate sensor – I used this PulseSensor one
- An Arduino – I used a Diecimilia
- A laptop running a Processing sketch that listen to the USB port (where I’ve plugged in my Arduino) and sucks in any data that arrives (see the helpful sparkfun tutorial).
Method
- Connect your PulseSensor to the Arduino. The physical set up looks like this (using the helpful PulseSensor getting started guide):
- 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:
- Nikki Pugh’s galvanic skin monitor mashed up with GPS data
- My Cake Orchestra which uses light-detectors hidden under cakes to play music via an Arduino and Processing
Places to buy kit
- Adafruit – especially good for tutorials and wearable electronics
- Sparkfun – ditto tutorials
- Cool components
- Lilypad Arduino (sewing- friendly Arduino):