Components · 12 min read

AD8232 Arduino ECG Tutorial: Electrodes, Wiring, Code and BPM

How to use the AD8232 with Arduino: RA, LA and RL electrode placement, LO+/LO- leads-off detection, a clean ECG in the Serial Plotter and BPM on an ESP32.

The AD8232 with Arduino is the easiest way to record a real ECG at home: this small module picks up the millivolt-level electrical signal your heart produces on every beat through three stick-on electrodes, then amplifies and filters it. Its output is read on a single analog pin, so with a few lines of code you can watch a genuine ECG trace on your computer, just like a hospital monitor: the P wave, the QRS complex and the T wave. Optical pulse sensors measure blood flow with light, while the AD8232 measures the heart's electricity directly, which is why it shows the moment of each beat far more sharply.

In this guide you'll learn how the AD8232 module works, where to stick the RA, LA and RL electrodes, how to detect a loose electrode with the LO+ and LO- pins, how to plot the ECG in the Serial Plotter with an Arduino Uno, how to filter out 50/60 Hz mains hum in software and how to calculate heart rate (BPM) on an ESP32. There's also MicroPython code for the Raspberry Pi Pico, a noise-source table, battery-powered safety and the most common mistakes. One important note before we start: this is an educational project, not a medical device.

What is the AD8232 and how is an ECG measured?

Before every contraction the heart muscle is electrically excited, and that excitation spreads through the body. The voltage between two electrodes on the skin is only about 1 mV, and on top of that your body picks up the mains voltage around it like an antenna, so the interference can be much larger than the heart signal. The AD8232 is an analog front-end chip that Analog Devices designed for exactly this job: it contains an instrumentation amplifier that measures the difference between two electrodes, an op-amp that amplifies and filters the signal further, and a right-leg drive that uses the third electrode (RL) to cancel the body's common-mode voltage. You can try out how op-amp gain is calculated with the Op-amp tool.

At the module's output you get a signal amplified roughly a thousand times and filtered to a band similar to an ECG monitor's (about 0.5–40 Hz). It swings around 1.65 V, half the supply, and the 1 mV R wave on the skin appears as a peak of around 1 V at the output. That's why an ordinary Arduino analog input can read the ECG comfortably. Most boards also have a small LED that blinks with the heart rhythm, so you can tell at first glance whether a signal is coming through.

FeatureValue
ChipAnalog Devices AD8232, single-lead heart signal front end
Supply3.3 V (the chip runs on 2.0–3.5 V)
CurrentAbout 170 µA for the chip; a little more with the on-board LED
Output (OUTPUT)Analog, 0–3.3 V, about 1.65 V at rest
Leads-off outputsLO+ and LO-, digital; HIGH when an electrode comes off
Electrodes3: RA (right arm), LA (left arm), RL (right leg)
Electrode connection3.5 mm jack or RA, LA, RL solder pads
SDN pinPull LOW for shutdown; can be left unconnected

Reading the ECG trace: P, QRS and T

Every part of the trace you'll see matches an event in the heart. Knowing them before you write any code helps you judge whether the signal is right and understand why the BPM algorithm only looks for the R wave.

PartWhat it showsTypical durationHow it looks on screen
P waveContraction of the atria80–100 msA small, rounded bump before the QRS
PR intervalThe impulse passing from atria to ventricles120–200 msThe flat section between P and QRS
QRS complexContraction of the ventricles80–120 msThe tallest, sharpest peak (the R wave)
T waveThe ventricles recovering for the next beatQT interval 350–450 msA wide, rounded bump after the QRS
RR intervalTime between two beats600–1000 ms at restFrom one R peak to the next; BPM = 60000 / RR

For example, if there are 800 ms between two R peaks, the heart rate is 60000 / 800 = 75 BPM. In a resting adult 60–100 BPM is considered normal, and in people who train regularly it can drop below 50. The AD8232 is single-lead, meaning it looks at the heart from one angle only; it doesn't replace a 12-lead hospital ECG, but it's more than enough to see the rhythm and the timing of each beat.

Electrode placement: where do RA, LA and RL go?

AD8232 kits usually come with a three-lead cable on a 3.5 mm jack and disposable, gel-backed sticky electrodes. The electrode names come from the arms and leg, but the strongest signal is on the chest, close to the heart. These are the two most common placements:

ElectrodeRoleChest placement (recommended)Arm and leg placement
RA (right arm)Measuring electrodeJust below the right collarboneInside of the right wrist
LA (left arm)Measuring electrodeJust below the left collarboneInside of the left wrist
RL (right leg)Reference and noise cancellingLower right abdomen or above the right hip boneInside of the right ankle

With the chest placement the electrodes sit close to the heart, so the trace is bigger and cleaner. The limb placement is handy for a quick test on a friend, but it's more affected by muscle movement. Cable colours vary from maker to maker, so don't trust the colour: trust the RA, LA and RL labels on the leads or on the module. If the R wave points down instead of up, swap RA and LA or invert the signal in code.

Before sticking on an electrode, wipe the skin with an alcohol pad and let it dry for a few seconds; lotion, sweat and body hair ruin the contact. Disposable Ag/AgCl gel electrodes give the best results. You can reuse the same electrode a few times, but as the gel dries the noise increases and the LO pins start triggering more often.

AD8232 wiring: Arduino Uno, ESP32 and Pico

AD8232 pinArduino UnoESP32Raspberry Pi Pico
GNDGNDGNDGND (pin 38)
3.3V3.3V3V33V3(OUT) (pin 36)
OUTPUTA0GPIO 34 (ADC1)GP26 / ADC0 (pin 31)
LO-D11GPIO 33GP15 (pin 20)
LO+D10GPIO 32GP14 (pin 19)
SDNNot connectedNot connectedNot connected
Don't connect the AD8232 module to 5V: the chip only runs up to about 3.5 V. On the Arduino Uno, take power from the 3.3V pin. Also, while the electrodes are attached to a person, never power the circuit from a wall adapter or a laptop that's charging; we explain why in the safety section below.

Because the Uno measures against a 5 V reference, the 1.65 V midpoint reads as about 338 with analogRead() and the signal stays within 0–675; that's normal. The ESP32 and Pico already run at 3.3 V, so you can connect the output directly. On the ESP32 the ADC2 pins can't be read while Wi-Fi is on, so we wired OUTPUT to GPIO 34 in the ADC1 group. You can check your board's layout with the pinout tool.

Step by step: your first ECG trace

  1. Wire the module as in the table and push the electrode cable fully into the 3.5 mm jack.
  2. Clean your skin, stick the three electrodes on using the chest placement and snap the RA, LA and RL leads onto them.
  3. Unplug your laptop's charger so it runs on battery during the measurement.
  4. Upload the sketch below, open Tools > Serial Plotter and set the speed to 115200 baud.
  5. Sit comfortably, rest your arms on your knees and wait 10–15 seconds without talking.
C++ (Arduino IDE)
1// AD8232 EKG: ham sinyal ve kopuk elektrot testi / raw signal and leads-off test
2const int ECG_PIN = A0;                 // AD8232 OUTPUT
3const int LO_PLUS = 10;                 // AD8232 LO+
4const int LO_MINUS = 11;                // AD8232 LO-
5const unsigned long PERIOD_US = 4000;   // 4 ms = saniyede 250 örnek / 250 samples per second
6
7unsigned long lastSample;
8
9void setup() {
10  Serial.begin(115200);                 // Serial Plotter'da da 115200 seç / pick 115200 in the Serial Plotter too
11  pinMode(LO_PLUS, INPUT);
12  pinMode(LO_MINUS, INPUT);
13  lastSample = micros();
14}
15
16void loop() {
17  if (micros() - lastSample < PERIOD_US) return;   // sıradaki örneği bekle / wait for the next sample
18  lastSample += PERIOD_US;                         // kaymayan sabit aralık / fixed interval without drift
19
20  bool leadsOff = digitalRead(LO_PLUS) == HIGH || digitalRead(LO_MINUS) == HIGH;
21  int ecg = leadsOff ? 0 : analogRead(ECG_PIN);    // kopukken 0 gönder / send 0 while an electrode is off
22
23  Serial.print("ECG:");
24  Serial.print(ecg);
25  Serial.print(",LO:");
26  Serial.println(leadsOff ? 600 : 0);              // kopuk elektrot çizgisi / leads-off line
27}

The sketch samples the signal exactly 250 times a second, once every 4 ms, which is enough to catch the QRS complex, the fastest part of the ECG. Because it advances time with lastSample += PERIOD_US, the spacing between samples doesn't drift. On every sample it first checks LO+ and LO-: if either is HIGH, an electrode has come off the skin, so the sketch sends 0 instead of the ECG and raises the LO line. With the electrodes in place you'll see sharp R peaks about once a second on the ECG line, sitting on a baseline around 300–400. If the Serial Plotter is new to you, our Arduino Serial Monitor guide explains how the window works.

Leads-off detection with LO+ and LO-

The AD8232's leads-off detection relies on a simple idea: the electrode inputs are pulled towards the supply through very high-value resistors. When an electrode is stuck firmly to the skin, the body and the RL electrode hold the input at mid-level. If the electrode falls off or its gel dries out, the input drifts towards the supply, a comparator in the chip notices and drives the matching LO pin HIGH. At the same time the OUTPUT pin sticks to a rail or wanders randomly, and if your code feeds those values into the BPM calculation you'll get nonsense. That's why checking the LO pins before every sample is a good habit. If only the RL electrode comes off, the LO pins won't always trigger, but the signal becomes noticeably noisier.

Noise sources and filter table

The filters on the AD8232 do most of the work, but at home the signal rarely arrives perfectly clean. The table below helps you recognise what's causing a distortion in the Serial Plotter from its shape and pick the right fix.

NoiseHow it looks on screenSourceFix
Mains hum (50/60 Hz)The line gets thick with a regular fine rippleSockets, adapters, fluorescent lights, long wiresRun the computer on battery, twist the leads together; in software, a moving average over one mains period
Muscle noise (EMG)Irregular, fuzzy spikesTensing your arms, talking, shiveringSit relaxed, place electrodes over bone rather than muscle; 40 Hz low-pass filter
Baseline wanderThe whole trace slowly drifts up and downBreathing, moving your torsoSubtract a slow average from the signal (about 0.5 Hz high-pass)
Motion artefactBig jumps, the line sticks to the top or bottomTugging the cable, electrode shiftingTape the cable down, stay still while measuring
Poor contactConstant noise, LO pins going HIGH now and thenDried gel, oily or hairy skinNew electrode, clean the skin with alcohol
USB and adapter noiseHigh-frequency, messy noiseCharger, low-quality USB cablePower from a battery or power bank

The most effective software trick against mains hum is a moving average. Averaging the samples taken over exactly one mains period (20 ms at 50 Hz) almost completely removes 50 Hz and its harmonics. If you choose a sampling rate of five times the mains frequency (250 Hz for 50 Hz, 300 Hz for 60 Hz), that average is exactly 5 samples. The price is slightly rounded R peaks, which doesn't matter for seeing the rhythm and the BPM. Baseline wander is fixed by subtracting a very slow average from the signal. For more filtering techniques, see our sensor data filtering guide.

C++ (Arduino IDE)
1// AD8232 + Arduino Uno: şebeke çentiği ve taban düzeltme / mains notch and baseline removal
2const int ECG_PIN = A0;                 // AD8232 OUTPUT
3const int LO_PLUS = 10;                 // AD8232 LO+
4const int LO_MINUS = 11;                // AD8232 LO-
5const int MAINS_HZ = 50;                // şebeke frekansı: 50 ya da 60 / mains frequency: 50 or 60
6const int N_AVG = 5;                    // bir şebeke periyodundaki örnek / samples per mains period
7const unsigned long PERIOD_US = 1000000UL / (MAINS_HZ * N_AVG);   // 250 Hz: 4000 µs, 300 Hz: 3333 µs
8const bool INVERT = false;              // R dalgası aşağı bakıyorsa true / true if the R wave points down
9
10int buf[N_AVG];                         // son 5 ham örnek / last 5 raw samples
11int bufIndex = 0;
12long bufSum = 0;
13float baseline = 0;                     // yavaş ortalama (taban) / slow average (baseline)
14unsigned long lastSample;
15
16void setup() {
17  Serial.begin(115200);
18  pinMode(LO_PLUS, INPUT);
19  pinMode(LO_MINUS, INPUT);
20  int first = analogRead(ECG_PIN);
21  for (int i = 0; i < N_AVG; i++) buf[i] = first;
22  bufSum = (long)first * N_AVG;
23  baseline = first;
24  lastSample = micros();
25}
26
27void loop() {
28  if (micros() - lastSample < PERIOD_US) return;
29  lastSample += PERIOD_US;
30
31  if (digitalRead(LO_PLUS) == HIGH || digitalRead(LO_MINUS) == HIGH) {
32    Serial.println("Raw:0,Filtered:0");            // elektrot kopuk / electrode off
33    return;
34  }
35
36  int raw = analogRead(ECG_PIN);
37  bufSum += raw - buf[bufIndex];                   // en eskiyi çıkar, yeniyi ekle / drop the oldest, add the newest
38  buf[bufIndex] = raw;
39  bufIndex = (bufIndex + 1) % N_AVG;
40  float smooth = (float)bufSum / N_AVG;            // 50/60 Hz paraziti silinir / 50/60 Hz hum removed
41  baseline += (smooth - baseline) * 0.01;          // ~0,4 Hz altını izler / tracks below ~0.4 Hz
42  float ecg = smooth - baseline;                   // taban kayması çıkarıldı / baseline wander removed
43  if (INVERT) ecg = -ecg;
44
45  Serial.print("Raw:");
46  Serial.print(raw - baseline, 0);                 // gürültülü ham sinyal / noisy raw signal
47  Serial.print(",Filtered:");
48  Serial.println(ecg, 0);                          // süzülmüş EKG / filtered ECG
49}
Constant / lineWhat it does
MAINS_HZ = 50Mains frequency; set it to 60 in the US, Canada and other 60 Hz countries. The sampling rate is five times this value.
N_AVG = 5Moving average window; it spans exactly one mains period, so it removes 50/60 Hz.
0.01Baseline tracking speed; at 250 Hz it removes slow changes below about 0.4 Hz (breathing, movement).
INVERTSet to true if the R wave points down; the signal is flipped.
Raw / FilteredTwo overlapping lines in the Serial Plotter: the noisy raw signal and the filtered ECG.

Calculating BPM with an ESP32

Now let's go beyond drawing the trace and calculate the heart rate. The idea behind the algorithm is simple: the QRS complex is the biggest, sharpest part of the ECG, so when the filtered signal crosses a threshold we assume a new beat has started. The threshold isn't fixed; the code follows the height of recent R peaks with a peak envelope and puts the threshold at half of that height, so it adapts when the electrode position or the person changes. Peaks arriving within 250 ms of a beat (usually the T wave) are ignored, which caps the measurable rate at 240 BPM and prevents double counting. BPM = 60000 / RR is calculated from the average of the last 8 RR intervals.

C++ (Arduino IDE)
1// AD8232 + ESP32: R dalgası algılama ve BPM / R-peak detection and BPM
2const int ECG_PIN = 34;                 // AD8232 OUTPUT, ADC1 pini / ADC1 pin
3const int LO_PLUS = 32;                 // AD8232 LO+
4const int LO_MINUS = 33;                // AD8232 LO-
5const int LED_PIN = 2;                  // çoğu DevKit'te dahili LED / built-in LED on most DevKits
6const int MAINS_HZ = 50;                // şebeke: 50 ya da 60 Hz / mains: 50 or 60 Hz
7const int N_AVG = 5;                    // bir şebeke periyodu = 5 örnek / one mains period = 5 samples
8const unsigned long PERIOD_US = 1000000UL / (MAINS_HZ * N_AVG);
9const float MIN_AMP = 150;              // 12 bitte en küçük R yüksekliği / minimum R height in 12-bit units
10const unsigned long REFRACTORY_MS = 250;  // iki atış arası en kısa süre (en fazla 240 BPM) / shortest gap between beats (max 240 BPM)
11const int AVG_BEATS = 8;                // ortalanan RR aralığı / RR intervals averaged
12const bool INVERT = false;              // R dalgası aşağı bakıyorsa true / true if the R wave points down
13
14int buf[N_AVG];
15int bufIndex = 0;
16long bufSum = 0;
17float baseline = 0, peakEnv = 0;        // taban ve tepe zarfı / baseline and peak envelope
18bool inBeat = false;                    // şu an R tepesinin içinde miyiz / are we inside an R peak
19unsigned long lastSample = 0, lastBeat = 0;
20unsigned long rr[AVG_BEATS];            // son RR aralıkları (ms) / last RR intervals (ms)
21int rrCount = 0, rrIndex = 0, bpm = 0;
22
23void resetBeats() {
24  rrCount = 0;
25  rrIndex = 0;
26  bpm = 0;
27  lastBeat = 0;
28  inBeat = false;
29  digitalWrite(LED_PIN, LOW);
30}
31
32void setup() {
33  Serial.begin(115200);
34  pinMode(LO_PLUS, INPUT);
35  pinMode(LO_MINUS, INPUT);
36  pinMode(LED_PIN, OUTPUT);
37  analogReadResolution(12);             // 0-4095 arası değer / values from 0 to 4095
38  int first = analogRead(ECG_PIN);
39  for (int i = 0; i < N_AVG; i++) buf[i] = first;
40  bufSum = (long)first * N_AVG;
41  baseline = first;
42  lastSample = micros();
43}
44
45void loop() {
46  if (micros() - lastSample < PERIOD_US) return;
47  lastSample += PERIOD_US;
48  unsigned long now = millis();
49
50  if (digitalRead(LO_PLUS) == HIGH || digitalRead(LO_MINUS) == HIGH) {
51    resetBeats();
52    Serial.println("ECG:0,Threshold:0,BPM:0");    // elektrot kopuk / electrode off
53    return;
54  }
55
56  int raw = analogRead(ECG_PIN);
57  bufSum += raw - buf[bufIndex];
58  buf[bufIndex] = raw;
59  bufIndex = (bufIndex + 1) % N_AVG;
60  float smooth = (float)bufSum / N_AVG;            // şebeke çentiği / mains notch
61  baseline += (smooth - baseline) * 0.01;          // taban takibi / baseline tracking
62  float ecg = smooth - baseline;
63  if (INVERT) ecg = -ecg;
64
65  // Zarf tepeye hemen çıkar, sonra yavaşça söner / the envelope jumps to a peak, then decays slowly
66  if (ecg > peakEnv) peakEnv = ecg;
67  else peakEnv *= 0.999;
68  float threshold = peakEnv * 0.5;                 // eşik: zarfın yarısı / threshold: half the envelope
69
70  if (!inBeat && peakEnv > MIN_AMP && ecg > threshold && now - lastBeat > REFRACTORY_MS) {
71    inBeat = true;                                 // yeni R tepesi / new R peak
72    if (lastBeat > 0 && now - lastBeat < 2000) {   // 2 s'den uzun boşlukları sayma / skip gaps over 2 s
73      rr[rrIndex] = now - lastBeat;
74      rrIndex = (rrIndex + 1) % AVG_BEATS;
75      if (rrCount < AVG_BEATS) rrCount++;
76      unsigned long sum = 0;
77      for (int i = 0; i < rrCount; i++) sum += rr[i];
78      bpm = (int)(60000UL * rrCount / sum);        // BPM = 60000 / ortalama RR / average RR
79    }
80    lastBeat = now;
81    digitalWrite(LED_PIN, HIGH);
82  } else if (inBeat && ecg < threshold * 0.5) {
83    inBeat = false;                                // R tepesi bitti / R peak is over
84    digitalWrite(LED_PIN, LOW);
85  }
86
87  if (lastBeat > 0 && now - lastBeat > 3000) resetBeats();   // 3 s atış yoksa sıfırla / reset after 3 s without a beat
88
89  Serial.print("ECG:");
90  Serial.print(ecg, 0);
91  Serial.print(",Threshold:");
92  Serial.print(threshold, 0);
93  Serial.print(",BPM:");
94  Serial.println(bpm);
95}

The ESP32's ADC is 12-bit (0–4095), so the midpoint reads around 2000 and MIN_AMP is set for the 12-bit scale. The code briefly lights the built-in LED on every R peak and resets the BPM if it sees no beat for 3 seconds. In the Serial Plotter you'll see three lines: the filtered ECG, the threshold following it and the BPM. The ESP32's real strength is wireless: you can send the BPM to a web page over WebSocket or to your phone over BLE, removing the cable between the circuit and the computer entirely. Since the code only uses analogRead and digitalRead, it compiles the same way on versions 2.x and 3.x of the ESP32 board package.

ECG with the Raspberry Pi Pico and MicroPython

On the Raspberry Pi Pico, power the module from the 3V3(OUT) pin, connect OUTPUT to GP26 (ADC0) and LO+ and LO- to GP14 and GP15. The MicroPython code below applies the same moving average and baseline correction and prints the values in a format you can watch in Thonny's plot window, opened from View > Plotter. read_u16() returns values from 0 to 65535; the code shifts them 4 bits right to bring them to the same 0–4095 scale as the ESP32. If MicroPython is new to you, start with our MicroPython basics guide.

MicroPython
1# AD8232 + Raspberry Pi Pico: MicroPython ile EKG / ECG with MicroPython
2from machine import ADC, Pin
3import time
4
5ecg_pin = ADC(26)                  # GP26 = ADC0, AD8232 OUTPUT
6lo_plus = Pin(14, Pin.IN)          # AD8232 LO+
7lo_minus = Pin(15, Pin.IN)         # AD8232 LO-
8
9MAINS_HZ = 50                      # şebeke: 50 ya da 60 Hz / mains: 50 or 60 Hz
10N_AVG = 5                          # bir şebeke periyodu = 5 örnek / one mains period = 5 samples
11PERIOD_US = 1000000 // (MAINS_HZ * N_AVG)
12
13buf = [ecg_pin.read_u16() >> 4] * N_AVG   # 0-4095 ölçeği / 0-4095 scale
14idx = 0
15baseline = buf[0]
16count = 0
17next_t = time.ticks_us()
18
19while True:
20    while time.ticks_diff(time.ticks_us(), next_t) < 0:
21        pass                       # sabit örnekleme aralığı / fixed sampling interval
22    next_t = time.ticks_add(next_t, PERIOD_US)
23
24    if lo_plus.value() or lo_minus.value():
25        print(0)                   # elektrot kopuk / electrode off
26        time.sleep_ms(100)
27        next_t = time.ticks_us()
28        continue
29
30    buf[idx] = ecg_pin.read_u16() >> 4
31    idx = (idx + 1) % N_AVG
32    smooth = sum(buf) / N_AVG      # şebeke çentiği / mains notch
33    baseline += (smooth - baseline) * 0.01   # taban takibi / baseline tracking
34    count += 1
35    if count % 2 == 0:             # Thonny yetişsin diye 2 örnekte bir yaz / print every 2nd sample so Thonny keeps up
36        print(int(smooth - baseline))

Battery power and safety

The electrodes connect you directly to the circuit. If the circuit is connected to the mains through a laptop, a fault or leakage current in the adapter could in theory reach your body through the electrodes. That's why medical devices are built to strict isolation and leakage-current limits; hobby modules have no such protection. The simplest precaution is to power the circuit only from batteries while measuring: unplug the laptop's charger, power the Arduino from a power bank, or run the ESP32 on a battery and send the data wirelessly. As a bonus, a circuit isolated from the mains picks up noticeably less 50/60 Hz hum.

The AD8232 itself draws only about 0.2 mA; the board is the real consumer. An Arduino Uno idles at 45–50 mA, and an ESP32 with Wi-Fi on averages 100–150 mA. A 2500 mAh 18650 cell runs a Wi-Fi ESP32 for roughly 15–20 hours including regulator losses; you can work it out for your own circuit with the battery life tool. If you charge the cell with a TP4056 charging module, always take the electrodes off while it's charging.

18650 Li-ion cell
18650 Li-ion cell: keeps the AD8232 and ESP32 circuit isolated from the mains, which is both safer and less noisy.
The circuits and code in this article are for education and hobby use only. AD8232 modules are not medical devices; don't diagnose, take medication or make treatment decisions based on the trace you see. If you have chest pain, palpitations, dizziness or shortness of breath, see a doctor right away, and in an emergency call your local emergency number. Don't experiment on anyone with a pacemaker or any other implanted device.

AD8232 or an optical pulse sensor?

Optical pulse sensors (Pulse Sensor, KY-039, MAX30102) measure changes in blood volume in the finger with light; they're easy to attach, but their waves are rounded and only show the moment of the beat approximately. Because the AD8232 measures the heart's electricity, it gives a sharp R peak on every beat, which makes it far more reliable for measuring RR intervals and heart rate variability (HRV). The price is sticking on three electrodes and dealing with noise. We cover the optical sensors in detail in our pulse sensor and MAX30102 guides.

Pulse Sensor optical heart rate sensor
Pulse Sensor: measures blood flow in the finger with green light; unlike the AD8232, it needs no electrodes.
FeatureAD8232 (ECG)Pulse Sensor (optical)MAX30102 (optical)
What it measuresThe heart's electrical signalBlood volume in the fingerBlood volume and blood oxygen (SpO2)
Attachment3 electrodesFingertip or earlobeFingertip
Beat timing sharpnessVery sharp (pointed R peak)Soft, rounded waveSoft, rounded wave
Interface1 analog + 2 digital pins1 analog pinI2C
Setup effortNeeds electrodes and skin prepVery easyEasy
Best forECG trace, rhythm, HRVSimple BPM readingsBPM and SpO2

AD8232 project ideas

  • Beeping heart monitor: Play a short beep with a buzzer on every R peak to mimic the sound of a hospital monitor.
  • OLED ECG display: Sweep the filtered trace from left to right on a 0.96-inch OLED display and show the BPM in the corner.
  • Wireless ECG: Run the ESP32 on a battery and send the samples to your computer over BLE or Wi-Fi; with no cable it's both safer and less noisy.
  • Heart rate variability (HRV): Take the differences between successive RR intervals, calculate the square root of the mean of their squares (RMSSD) and compare rest with stressful moments.
  • ECG logger: Write the samples with timestamps to an SD card, then explore them in a spreadsheet on your computer.
  • Recovery test: After climbing stairs, measure how many seconds it takes for your BPM to return to its resting value and track how it changes over the days.

Common mistakes and fixes

SymptomLikely causeFix
Always 0 in the Serial PlotterLO+ or LO- is HIGH: an electrode has come off or the jack isn't fully inPush the jack all the way in, replace the electrodes, check the LO wires
Signal stuck at the top or bottomWrong supply, OUTPUT on the wrong pin or constant movementCheck the 3.3 V and A0 connections, keep still
Thick, rippling line50/60 Hz mains humRun on battery, twist the leads, set MAINS_HZ for your country
R wave points downRA and LA are swappedSwap the electrodes or set INVERT = true
BPM shows doubleThe T wave is also counted as a beatRaise the threshold ratio from 0.5 to 0.6, move the electrodes to the chest
BPM keeps jumpingMuscle noise or movementSit relaxed, don't talk, increase AVG_BEATS
When troubleshooting, always start with the first raw-signal sketch. If you see a proper ECG trace there, the hardware is fine and the problem is in the filter or the threshold; if there's no trace, changing the code won't help, so fix the wiring and electrode contact first.

The AD8232 is one of the rare modules that teaches you the core ideas of signal processing, such as analog reading, fixed-interval sampling, digital filtering and peak detection, using your own heartbeat. You can practise analog reading, buzzer alerts and showing data on an OLED display step by step, with circuit diagrams and code, in the related projects in the BlueGrays app, and then add them to the ECG circuit from this article.

Frequently asked questions

Can the AD8232 record a real ECG?

Yes, the AD8232 really measures the heart's electrical signal and can show the P, QRS and T waves on screen. However, it's single-lead and not approved as a medical device, so it doesn't replace a 12-lead clinical ECG and must not be used for diagnosis. It's well suited to learning, rhythm experiments and measuring BPM.

Where do you put the AD8232 electrodes?

For the cleanest signal, place RA just below the right collarbone, LA just below the left collarbone and RL on the lower right abdomen or above the right hip bone. For the limb placement, RA goes on the right wrist, LA on the left wrist and RL on the right ankle; it's more convenient but weaker and noisier. Cleaning the skin with alcohol first makes a big difference.

Why does my AD8232 only show noise or a flat line?

A flat line usually means the LO pins have triggered, so an electrode isn't making contact; check the electrodes and the jack. A thick, rippling line is mains hum: unplug the laptop charger and use the moving average filter. If the signal is stuck at the top or bottom, the supply or OUTPUT wiring is probably wrong.

Does the AD8232 work with 5V?

No, the AD8232 chip runs on 2.0–3.5 V and the module must be powered from 3.3 V. On an Arduino Uno, use the 3.3V pin; the output stays between 0 and 3.3 V, so it can go straight into the Uno's analog input. The LO+ and LO- outputs are 3.3 V logic too, and the Uno reads them as HIGH without problems.

How do you calculate heart rate (BPM) with the AD8232?

The code catches the sharpest peak of each beat, the R wave, with an adaptive threshold and measures the time between two R peaks (the RR interval) in milliseconds. BPM is calculated with BPM = 60000 / RR, so an RR interval of 800 ms gives 75 BPM. Averaging the last 8 intervals gives a steadier reading.

Can AD8232 electrodes be reused?

Disposable gel electrodes can be reused for a few sessions, but as the gel dries the contact gets worse, noise increases and the LO pins trigger more often. Use fresh electrodes for longer sessions. Dry metal electrodes or wrist straps also work, but they pick up more noise.

See all projects
Measuring Light Intensity with an LDR
AR-11Beginner

Measuring Light Intensity with an LDR

Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

4.5(86)
154
Reading Light Intensity with the ESP32 LDR Module
ES-11Beginner

Reading Light Intensity with the ESP32 LDR Module

Real-time monitoring of the LDR module's raw ADC value and relative light percentage calculated from dark and light reference values in the Serial Monitor. This percentage is not a lux measurement. Teaches the module’s calibration logic. It is ideal to complete this before Project 10, as it is used to determine the threshold value.

4.6(36)
56
Using a Buzzer
AR-13Beginner

Using a Buzzer

Ever wondered how a doorbell or an alarm makes its sound? The Arduino makes a small buzzer beep at short intervals: beep, pause, beep, pause.

4.7(93)
184
Digital Voltmeter with LCD Display
AR-56Intermediate
Premium

Digital Voltmeter with LCD Display

Find out how much voltage a battery or power adapter gives with a meter you built yourself.

4.5(27)
36
ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)
ES-13Intermediate
Premium

ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)

In this project, we control the brightness of an LED analogically using a potentiometer. The ESP32's ADC pin reads the 0-3.3V voltage from the potentiometer, and this value is then converted into a PWM (Pulse Width Modulation) signal and sent to the LED. As a result, as you turn the potentiometer, the LED gradually brightens and dims. With Arduino Core 3.0+, analogWrite() can be used directly; on the ESP32-S2/S3, the ADC resolution is fixed at 12-bit.

4.4(20)
32
ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)
ES-32Advanced
Premium

ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)

In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. Unlike the I2C LCD version, it uses an SSD1306 OLED (128×64) display, with large text and vector icons for a richer look. Seven weather icons (sunny, rainy, snowy and more) are drawn on the fly, with no bitmap files.

4.3(10)
22
ESP32 Deep Sleep — Battery Saving (OLED + RTC RAM Counter)
ES-33Advanced
Premium

ESP32 Deep Sleep — Battery Saving (OLED + RTC RAM Counter)

The ESP32's Deep Sleep mode shuts down the CPU and most peripherals, cutting current draw to about 10µA, which is vital for battery-powered IoT devices. This project uses three wake-up sources: a timer (15 s), an external pin (EXT0, the button on GPIO 33) and a touch pin (T0/GPIO 4). Counters marked with RTC_DATA_ATTR survive deep sleep.

4.3(10)
17
ESP32 Temperature Data Logger (DHT22 + DS1307 RTC + microSD + OLED)
ES-40Advanced
Premium

ESP32 Temperature Data Logger (DHT22 + DS1307 RTC + microSD + OLED)

Build a timed temperature and humidity logger with the ESP32! A DHT22 sensor reads temperature and humidity once a minute, and each reading is saved to a microSD card in CSV format with a real-time stamp from the DS1307 RTC module. The OLED display shows the latest temperature, humidity, timestamp and total number of records live, in large text.

4.7(7)
12