Heart Rate Monitor using Android and Arduino

Last week I decided to buy some stuff from local reseller of Arduino. I bought a Kyto Heart Sensor that transmits heart pulses to a receiver via radio frequency. The RF receiver can then be interfaced to an arduino and then pass the results to an Android device for visualization.

I’ve used the same Sketch from Seeduino website and just modified it a little bit for ADK.

Setup

In the setup function, the most interesting part is the use of attachInterrupt function. What it does is it binds a callback that will be called when a RISING signal is detected on interrupt 0 which is digital port 2 in Arduino. More details about attachInterrupt  on the Arduino documentation. So the data pin in our RF receiver should go to pin 2 in Arduino. Each time the receiver receives a heart pulse from the sensor, it triggers the interrupt and calls the callback function “interrupt”.

Loop

For the loop part, I don’t really understand why it needs to call digitalWrite on pin 13 even though there’s nothing connected on that pin.

Finally, the interrupt function simply collects the timings for consecutive 20 heart beats and sums it up and will be sent  to Android device via AndroidAccessory.write call.

So for each heartbeat, I am also sending a signal to Android device so that we can make some visualizations such as a heart beating and some cool graph.

In the application side, everything is straightforward. The only thing that’s a bit difficult to carry out is the graph view. After the Android device receives the data from Arduino, it will just execute an animation on the heart image to simulate heart pumping and then draw a signal on the chart. For each 20 consecutive heart pulse, Arduino will send the computed heart rate value to the Android device and we just need to update the value of our TextView via setText call.