AD8232 heart monitor (ECG)

The AD8232 single-lead heart monitor: three electrodes and a gain of 1100 that put the heart's signal on one analog wire. Aliases: ECG sensor, EKG, AD 8232.

The AD8232 is an instrumentation amplifier (gain 100), an op amp (gain 11 more), filters for the electrodes' drift and the mains, and a buffer holding the signal's middle at half the supply. A heartbeat at the skin is about a millivolt, so on OUTPUT it is about a volt: around 1.65 V on a 3.3 V supply, the R wave rising a volt above it.

The heartbeat is synthetic. Mokxi builds each beat from the P wave, Q, R, S and the T wave at the places and sizes they have on a healthy lead I trace. It is not a recording of anyone, and the board's face says so.

Pins

Pin What it does
GND Ground.
3.3V Supply, 2.0 V to 3.5 V. Use the board's 3.3 V pin, not 5 V.
OUTPUT The ECG, centered on half the supply. Read it with analogRead().
LO- High when the RA (right arm) electrode is off.
LO+ High when the LA (left arm) electrode is off.
SDN Low shuts the chip down. The board holds it high, so it can stay unwired.

Properties

bpm is the heart rate, 30 to 220 beats a minute (72 by default). noise is how much muscle noise and baseline wander ride on the trace, 0 to 100 percent; 10 is someone sitting still. electrodes starts with all of them on, or one or both off.

While it runs

The top slider is the heart rate and the one under it the noise. The leads key takes electrodes off and puts them back: LA off, RA off, all off, all on. The heart on the board beats with each R wave.

What the model gets right

The middle and the size. OUTPUT sits at half the supply, 338 counts on an Uno reading a 3.3 V board against its 5 V reference, and the R wave rises about 225 counts above it.

The shape. A small P wave, a dip (Q), the tall R wave, a dip (S), then the broad T wave. The T wave moves in closer to R as the heart speeds up, by the square root of the beat interval, as Bazett's formula has it.

Lead off. With an electrode off, its lead-off pin goes high and the amplifier saturates: OUTPUT goes to the top rail with LA off, the bottom rail with RA off. That is why every sketch checks LO+ and LO- before trusting a reading.

The rate. R waves come exactly 60000 / bpm milliseconds apart.

What it does not model

The filters' own shaping of the beat (the trace already has the shape that comes out), the fast-restore circuit, the right-leg drive, the small changes from beat to beat of a real heart, and any arrhythmia. A real board's output wanders as an electrode comes off; this one goes straight to the rail. Nothing here is a medical device, and neither is the real board.

Example

void setup() {
  Serial.begin(9600);
  pinMode(10, INPUT);   // LO+
  pinMode(11, INPUT);   // LO-
}

void loop() {
  if (digitalRead(10) == HIGH || digitalRead(11) == HIGH) {
    Serial.println('!');
  } else {
    Serial.println(analogRead(A0));
  }
  delay(1);
}

Open the Plot pane to see the trace.

Common mistakes

Powering it from 5 V. The chip is rated to 3.5 V; use the 3.3 V pin.

Printing too slowly. At 9600 baud each line takes about 5 ms, fast enough for an ECG; adding delay(100) turns the trace into dots.

Expecting the middle to be 512. The board's middle is half of its own 3.3 V supply, which an Uno reads as about 338.

See it in action

ECG heart monitor plot draws the trace in the Plot pane. Open it at /templates.