Ecg Sensors
Ecg Sensors
Introduction
The AD8232 is a neat little chip used to measure the electrical activity of the heart. This electrical
activity can be charted as an ECG or Electrocardiogram. Electrocardiography is used to help
diagnose various heart conditions. Now for the disclaimer:
NOTE: This device is not intended to diagnose or treat any conditions.
Credit Wikipedia.org
Diagram of the heart. Credit Wikipedia.org
PR Interval
The PR interval is the initial wave generated by an electrical impulse traveling from the right atrium
to the left. The right atrium is the first chamber to see an electrical impulse. This electrical impulse
causes the chambers to "depolarize". This forces it to contract and drain deoxygenated blood from
both the Superior and Inferior vena cava into the right ventricle. As the electrical impulse travels
across the top of the heart it then triggers the left atrium to contract. The left atrium is responsible for
receiving newly oxygenated blood from the lungs into the left ventricle via the left and right
pulmonary veins. The pulmonary veins are red in the diagram because they are carrying oxygenated
blood. They are still called veins because veins carry blood towards the heart. Science!
QT Interval
The QT Interval is where things get really interesting. The QRS is a complex process that generates
the signature "beep" in cardiac monitors. During QRS both ventricles begin to pump. The right
ventricle begins to pump deoxygenated blood into the lungs through the left and right pulmonary
arteries. The pulmonary arteries are blue in the diagram because they are carrying deoxygenated
blood. They are still called arteries because arteries carry blood away the heart. Science, Again! The
left ventricle is also begining to pump freshly oxygenated blood through the aorta and into the rest of
the body. After the initial contraction comes the ST segment. The ST segment is fairly quiet
electrically as it is the time where the ventricals waiting to be "re-polarized". Finally the T wave
becomes present to actively "re-ploarize", or relax the ventricles. This relaxation phase resets the
ventricles to be filled again by the atriums.
Pin Connections
The AD8232 Heart Rate Monitor breaks out nine connections from the IC. We traditionally call these
connections "pins" because they come from the pins on the IC, but they are actually holes that you
can solder wires or header pins to.
We'll connect five of the nine pins on the board to your Arduino. The five pins you need are
labeled GND, 3.3v, OUTPUT, LO-, and LO+.
Headers installed
Circuit Diagram
Follow the diagram below, to make necessary connections. The SDN pin is not used in this demo.
Connecting this pin to ground or "LOW" on a digital pin will power down the chip. This is useful for
low power applications.
Connection Diagram
Cable ColorSignal
Black RA (Right Arm)
Blue LA (Left Arm)
Red RL (Right Leg)
Typical Sensor Placements
Arduino Example
Note: This code has been written and tested on Arduino IDE version v1.0.5. Otherwise, make sure
you are using the latest stable version of the Arduino IDE on your desktop. If this is your first time
using Arduino, please review our tutorial on installing the Arduino IDE. Also, make sure to check out
the following tutorials before uploading code: How to Install FTDI Drivers and Using the Arduino Pro
Mini 3.3V.
By this point, you should have the hardware connected and ready. The example sketch can be
found in the GitHub repository.
GITHUB: AD8232 HEART RATE MONITOR/.../HEART_RATE_DISPLAY_ARDUINO.INO
You can cut and paste the code straight from GitHub or clone the repository and open the file. Make
sure to select the correct board (i.e. Arduino Pro Mini 3.3V/8MHz) and COM port. When you are
ready, hit the upload button to upload the code to your board.
Upload Sketch to Arduino Pro Mini 3.3V/8MHz
To verify that the heart rate monitor is working as expected, open the serial monitor at 9600 baud.
You should see values printed on the screen. Below is an example output with the sensors
connected on the forearms and right leg. Your serial output should spike between +300/-200 around
the center value of about ~500.
The serial data is hard to visualize if you are just viewing the values. If you are using Arduino IDE
v1.6.6+, there is an option to view the data on a graph using the Arduino Serial Plotter as one option.
In the Arduino IDE, select Tools > Serial Plotter. You should see a waveform similar to the image
below when the sensors are placed correctly and not moving.
Processing Example
Heads Up! This Processing Sketch is for advanced users! For those that are new to programming,
you may just want to use the Arduino Serial Plotter. For those that have experience programming
and have used Processing before, feel free to continue on!
Note: Processing is a software that enables visual representation of data, among other things. If
you've never dealt with Processing before, we recommend you also check out the Arduino to
Processing tutorial. Follow the button below to go ahead and download and install Processing IDE
v2.2.1. The following examples were intended for Processing IDE v2 so you may have issues getting
it running on Processing IDE v3.
The Processing example code will give you another option to visualize the output of what's going on.
The example processing sketch can be found in the GitHub repository as well.
GITHUB: AD8232 HEART RATE MONITOR/.../HEART_RATE_DISPLAY.PDE
The example Processing sketch works with the Processing IDE v2.2.1. Later versions may not work
with the example code so makes sure to download the stable release for v2.2.1 from the Processing
IDE Download page. When ready, press the "Run" button.
The Arduino shows up as COM38. This is found in the Serial List at array element "2".
Once the COM port is adjusted with your setup, hit the Run button again. If everything is working
correctly, you should see a nice box pop up and start displaying the output signal similar to the
image below.
"Normal" heart rate of an SFE engineer
If your subject decides to remove the sensors, the leads off detection in the code will kick in and
display a flat blue line.
If the sensor pads are not placed correctly on the body or the cable is not connected, you may see
an output similar to the image below in the serial monitor. The values will either clip the waveform
between 0 and 1023 or display an "!".
As a result, you will either see a flat line in the Arduino serial plotter or nothing will be drawn in the
Processing's display window. If this happens, you'll need to check your solder joints and try placing
the sensor pads to a different location around the body.
If you happen to moving a lot or flex your muscle, you will not get a distinct waveform. Make sure to
remain still and relax as the sensor is taking measurements. You may see a few distinct waveforms
but it will not be as reliable.