Projects / ECG heart signal plotter

ECG heart signal plotter

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Unplug your laptop charger

    Battery power only.

  2. NANOAD823270 bpm

    Wire the AD8232 to the Nano

    3.3 V, A0, D10, D11.

  3. NANOAD823270 bpm

    Upload the sketch

    Nano board and port.

  4. NANOAD823270 bpm

    Clean and dry the skin

    Where the pads go.

  5. NANO

    Place the pads

    RA, LA, RL as in the notes.

  6. NANO

    Open the Serial Plotter

    115200 baud.

  7. NANOAD823270 bpm

    Sit still and watch the trace

    Look for the R peaks.

  8. NANO

    Compare the bpm with a pulse count

    Count your wrist pulse for 30 seconds.

In short

How do you build an ECG heart signal plotter?

An AD8232 board picks up the heart's tiny electrical signal from three chest pads and plots the waveform with a heart-rate estimate, for learning only. You need Arduino Nano, Heart rate and ECG sensor AD8232, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
AD8232 3.3V and GNDNano 3V3 and GNDPower the board from 3.3 V only
AD8232 OUTPUTNano A0Analog ECG signal
AD8232 LO+Nano D10Lead-off detect
AD8232 LO-Nano D11Lead-off detect
AD8232 SDNLeave unconnectedShutdown pin, not used
Electrode cable RA, LA, RLAD8232 jack, pads on chest as described in the notesRight arm, left arm, right leg reference
USB cableBattery-powered laptop only, never a laptop that is plugged into mainsPower and data

Code

Each heartbeat makes a tiny voltage, a millivolt or so, across your chest. The AD8232 board amplifies that about a thousand times and filters it, and the Nano samples it 250 times a second. Because 50 Hz mains hum is the main noise, the sketch averages every 5 samples: five samples at 250 Hz last exactly 20 ms, one full cycle of 50 Hz, so the hum cancels itself. Three sticky electrode pads go on the body: RA below the right collarbone, LA below the left collarbone and RL on the lower right ribs, matching the colours on the cable. Pat the skin dry first, and do not move while you watch the trace. SAFETY: run this only from a laptop that is on its own battery with the charger unplugged, because a mains-connected laptop can put an unsafe path between mains and your chest. A USB isolator adds protection. Power the board from the Nano's 3.3 V pin and never from any outside supply. This is a learning toy for seeing what an ECG looks like. It is not a medical device, it cannot detect heart problems, and its heart rate is only a rough estimate. If you feel unwell, see a doctor. Setup: Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails). Open Tools, Serial Plotter at 115200 baud.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// ECG plotter for the AD8232 board. LEARNING ONLY: this is not a medical device.
const uint8_t PIN_ECG = A0, LO_PLUS = 10, LO_MINUS = 11;
const unsigned long SAMPLE_US = 4000UL;      // 250 samples per second

int buf[5];                                   // 5 samples at 250 Hz is 20 ms: a 50 Hz hum cancels
uint8_t idx = 0;
long sum = 0;
unsigned long nextSample = 0, lastBeat = 0, winStart = 0;
int bpm = 0, thr = 512, mx = 0, mn = 1023, prevF = 0;

void setup() {
  Serial.begin(115200);
  pinMode(LO_PLUS, INPUT);
  pinMode(LO_MINUS, INPUT);
  nextSample = micros();
}

void loop() {
  if ((long)(micros() - nextSample) < 0) return;
  nextSample += SAMPLE_US;

  if (digitalRead(LO_PLUS) || digitalRead(LO_MINUS)) {   // a pad has come off
    Serial.println("0,0");
    return;
  }
  int raw = analogRead(PIN_ECG);
  sum -= buf[idx];
  buf[idx] = raw;
  sum += raw;
  idx = (idx + 1) % 5;
  int f = sum / 5;                                        // moving average removes mains hum

  unsigned long now = millis();
  if (now - winStart > 2000) {                            // every 2 s, set a new beat threshold
    thr = mn + (long)(mx - mn) * 6 / 10;
    mx = 0; mn = 1023; winStart = now;
  }
  if (f > mx) mx = f;
  if (f < mn) mn = f;
  if (prevF < thr && f >= thr && now - lastBeat > 300) {  // upward crossing of the threshold
    if (lastBeat) bpm = 60000UL / (now - lastBeat);
    lastBeat = now;
  }
  prevF = f;

  Serial.print(f);                                        // open the Serial Plotter to see the trace
  Serial.print(',');
  Serial.println(bpm);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

102,0
205,0
307,0
409,0
512,0
511,0

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Pads off the bodyPlot shows zero (leads off)
Pads on and sitting stillRepeating spikes appear
Count your pulse for 30 seconds and double itWithin a few beats of the bpm
Move your armTrace jumps, as expected
Plug in a laptop chargerDo not do this; test only on battery

If it does not work

Noisy, wandering trace

Dry the skin, press the pads, sit still, keep cables from swinging.

No R peaks

Check pad positions and the RL pad.

Bpm jumps

Threshold too low; sit still for a few seconds while it adapts.

Plot flat at 0

A lead is off or a pad is dry.

Heavy hum

Keep away from mains cables and chargers.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ECG heart signal plotter?

Arduino Nano, Heart rate and ECG sensor AD8232, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm).

How long does the ECG heart signal plotter take to build?

About 120 minutes for a intermediate maker, in 8 steps.

How do I know the ECG heart signal plotter works?

Pads off the body: Plot shows zero (leads off). Pads on and sitting still: Repeating spikes appear. Count your pulse for 30 seconds and double it: Within a few beats of the bpm.

Noisy, wandering trace: what should I check?

Dry the skin, press the pads, sit still, keep cables from swinging.

No R peaks: what should I check?

Check pad positions and the RL pad.

Bpm jumps: what should I check?

Threshold too low; sit still for a few seconds while it adapts.

Plot flat at 0: what should I check?

A lead is off or a pad is dry.