DIY EKG Using Arduino and Javascript
2016-08-04 | By Ben Dixon
License: None Arduino
This is an abstract only. For full project details, see DIY EKG Using Arduino and Javascript.
An Electrocardiogram (EKG or ECG) is a recording of the electrical activity of the heart to measure the rate and regularity of the heartbeat. For this project, we use a $25 Olimex EKG module, a set of electrodes for around $10 and, of course, Arduino Uno, which you might already have. The goal is to generate the heart’s waveform at home and then manipulate and plot it in real time using Javascript.
Disclaimer: This project was solely an experiment and should not replace professional medical attention. Nothing here is suitable for medical use. The EKG shield has not been certified and attaching electrodes to yourself could result in electric shock or seizure, continue at your own risk!
Components needed:
- Olimex EKG Shield
- Three electrodes (board compatible)
- Arduino Uno
This project was built on OSX, but it uses a Google Chrome App to interface with the Arduino so it should work on any platform supporting these. The manual for the Olimex board is excellent, covering the jumper configurations required for basic use. They provide the Arduino sketch responsible for reading from the analog inputs and writing out the data to the Serial port, which, by the way, is set to 57600 rather than the usual 9600. The data is written in binary format, so it cannot be viewed with standard Arduino Serial monitor. Windows software is provided, but I wrote my own.
App Code
My favourite tool at the moment for working with an Arduino is a Chrome App, which allows native-like apps to be created using standard html and javascript. Here is the chrome app source code I created for this project. It reads in data from the Arduino and charts it in real time.
To install the app in Chrome, clone the repository and then see the "load the extension" section of this page. Then install this sketch to Arduino. It sends packets of data as a stream of bytes. This means 17 bytes in total, with the first two being 165,90 and the last being a 1. The Chrome App then breaks the incoming stream into valid packets. Each of the analog readings within a packet are stored as unsigned 16-bit integers, they need to be reconstructed from the pairs of bytes received.
The app then uses CanvasJS to chart the data in real time. At the moment only one channel is displayed.
Arguably the hardest part of this project was getting adequate contact between the electrodes and the skin.
Next steps:
- Automatic peak detection
- Heart rate calculation
- Heart rate variability calculation