Showing posts with label PPG. Show all posts
Showing posts with label PPG. Show all posts

Friday, 27 November 2026

ECG, EEG, EMG and PPG Sensors: How They Work and How to Interface Them with ESP32

Standard

 

Your body is a quiet radio. The heart, brain, muscles, eyes, and skin all produce tiny electrical or optical signals. Hospitals read them with clinical machines. Makers now read a simplified version of the same idea with breakout boards and an ESP32. That does not make a hobby kit a medical device. It does make the signals learnable, if you put the right Analog Front-End (AFE) between the electrode and the microcontroller.

This post covers ten common electrical and physiological sensors: ECG, EEG, EMG, EOG, ERG, EGG, ENG, EDA/GSR, bioimpedance (BIA/ICG), and PPG. It then answers the practical question: can they all talk to an ESP32? Yes, with an AFE or a dedicated breakout. Direct electrode-to-GPIO wiring is how you get noise, bad data, and, if you stay plugged into mains, a safety problem (SparkFun, 2024; Texas Instruments, 2017).

Key Abbreviations in This Post

  • ECG (Electrocardiography): Electrical activity of the heart.
  • EEG (Electroencephalography): Brain-wave activity from the scalp.
  • EMG (Electromyography): Electrical activity of skeletal muscle.
  • EOG (Electrooculography): Potential changes around the eyes from eye movement.
  • ERG (Electroretinography): Electrical response of the retina to light.
  • EGG (Electrogastrography): Slow electrical rhythms of the stomach.
  • ENG (Electroneurography): Conduction along peripheral nerves, often with a stimulus.
  • EDA / GSR: Electrodermal activity / galvanic skin response. Skin conductance from sweat glands.
  • BIA / ICG: Bioimpedance analysis / impedance cardiography. How tissue resists a tiny AC current.
  • PPG (Photoplethysmography): Optical measure of blood-volume change, heart rate, and often SpO₂.
  • AFE (Analog Front-End): The amp, filter, and often ADC chip between electrodes and a microcontroller.
  • ESP32: Espressif Wi-Fi/BLE microcontroller family, common in battery-powered IoT projects.
  • ADC: Analog-to-digital converter. Turns a voltage into a number.

The One-Minute Version

  • Ten signals, two physics stories: most are biopotentials (microvolts to millivolts). PPG is light. BIA injects a safe AC current and measures impedance.
  • ESP32 can host all of them if an AFE or breakout sits in the middle. Never wire bare electrodes to ADC pins and call it done.
  • Easy start: AD8232 (ECG), MyoWare (EMG), BioAmp EXG (ECG/EMG/EOG/EEG-class), Grove GSR (EDA), MAX30102 (PPG).
  • Harder: EGG, BIA/ICG, ENG, ERG. Same ESP32, more specialized chips, filters, electrodes, or a stimulator.
  • Safety rule: while electrodes are on a person, power from a battery and send data over Wi-Fi or BLE. Unplug USB from the wall and from a charging laptop (SparkFun, 2024).
  • Scope: education, research prototypes, and wearables experiments. Not diagnosis or treatment.
Ten body signals: ECG EEG EMG EOG ERG EGG ENG EDA BIA PPG

What These Sensors Actually Measure

Clinicians group them by organ. Engineers group them by signal size and frequency. Both views help when you pick an AFE.

Signal, roughly where it lives, roughly how big Sensor Source Typical use Order of size ECG Heart muscle Rhythm, rate, waveform ~0.5 to 5 mV EEG Brain (scalp) Sleep, seizures, attention ~10 to 100 µV EMG Skeletal muscle Activation, fatigue, rehab ~50 µV to few mV EOG Eye dipole Gaze, blinks, REM sleep ~0.05 to 3.5 mV ERG Retina Photoreceptor response µV to low mV EGG Stomach Gastric slow waves ~100 to 500 µV ENG Peripheral nerve Conduction speed/strength µV range + stimulus EDA/GSR Sweat glands Stress, arousal Conductance change BIA/ICG Tissue / blood Composition, stroke volume Impedance ohms PPG Blood volume (light) HR, SpO₂, wearables Optical, not volts Rule of thumb Smaller and slower signals need more gain, quieter ADCs, and better filtering. EEG and EGG are harder than ECG. PPG is easiest for a first ESP32 wearable.
Body map of where ECG EEG EMG EOG and other biosignals are measured

Each Sensor, From Basics to Use

ECG: heart electricity

ECG records the depolarization wave as it moves through the atria and ventricles. A basic single-lead hobby setup shows rate and a rough QRS shape. A clinical 12-lead study maps the heart in more detail for ischemia and rhythm diagnosis (Goldberger et al., 2017). On an ESP32, the common module is the Analog Devices AD8232 heart-rate monitor front-end: three disposable electrodes, an analog output into an ADC pin (Analog Devices, 2012).

EEG: brain waves from the scalp

EEG is smaller than ECG by an order of magnitude or more. Frequency bands (delta, theta, alpha, beta, gamma) get used in sleep studies, epilepsy work, and research BCIs. A DIY board will not replace a clinical EEG lab. It can teach sampling, referencing, and how much 50/60 Hz mains noise lives on a scalp (Niedermeyer & Lopes da Silva, 2005). Multi-channel setups often use the TI ADS1299 over SPI.

EMG: muscle activation

Surface EMG listens to motor-unit firing under the skin. Rehab, gesture control, and sports science all use it. MyoWare-class modules rectify and smooth the signal into an envelope that an ESP32 can sample slowly. Raw EMG needs a wider bandwidth and a quieter front-end (Merletti & Parker, 2004; SparkFun, 2024).

EOG: eye movement

The eye is a dipole. Move the gaze, and the potential between electrodes near the canthi or above/below the eye changes. Sleep labs use EOG for REM. HCI experiments use it for blink and glance detection. Electrically it looks a lot like a slow ECG/EEG cousin, so BioAmp EXG or a re-filtered AD8232 often appears in maker builds.

ERG: retina response

ERG needs a light flash (or pattern) synchronized with the recording. Electrodes may be corneal or skin-based depending on the protocol. The electronics resemble other biopotential AFEs. The hard parts are optics, timing, and electrode type, not the ESP32 itself (McCulloch, 2019).

EGG: stomach rhythms

Gastric slow waves sit around a few cycles per minute. That means ultra-low-frequency filters (on the order of 0.01 to 0.5 Hz) and patience with motion artifact. You can reconfigure an ADS1299 or build an instrumentation-amp front-end. This is advanced DIY, not a weekend Amazon kit.

ENG: nerve conduction

ENG often stimulates a peripheral nerve and measures the compound action potential downstream. That means a safe, controlled stimulator plus a high-gain low-noise amp. An ESP32 can time the stimulus and log the response. Designing the stimulator is the real project, and safety review matters more than the Wi-Fi stack.

EDA / GSR: skin conductance

Sweat-gland activity changes how well the skin conducts. Stress and arousal studies use this a lot. Grove-style GSR modules are a voltage divider the ESP32 can read on an ADC pin. The signal is slow. Motion and electrode dryness matter more than sample rate.

BIA / ICG: bioimpedance

A tiny AC current is injected. The measured impedance relates to body composition (BIA) or, in thoracic setups, to blood-flow related changes (ICG). Chips such as Analog Devices AD5933 (I2C impedance converter) or Maxim MAX30001 (SPI) exist for this. Do not invent your own current-injection circuit without reading the safety limits in the datasheet (Analog Devices, 2017).

PPG: light, not electrodes

PPG shines LEDs into tissue and reads the reflected or transmitted light with a photodiode. Heart rate and SpO₂ wearables live here. MAX30102 / MAX30105 breakouts talk I2C to the ESP32 and are the friendliest first biosensor for most makers (Maxim Integrated, 2015).

ECG EEG EMG and EOG measurement sites on the body

Can an ESP32 Interface All of Them?

Yes, as a host. No, as a raw electrode ADC.

Biopotential amplitudes sit in the microvolt to millivolt range. The ESP32's GPIO and on-chip ADC expect volts-scale swings and are noisy near the rails. The missing piece is an AFE: gain, filtering, often driven-right-leg or bias, and preferably a dedicated ADC. Optical and impedance sensors already ship as digital breakouts, so the ESP32 only needs I2C or SPI (Espressif, 2023; Texas Instruments, 2017).

Problem: a student clips ECG electrodes to GPIO36 and sees garbage.
Cause: the heart signal is about a millivolt, buried in electrode offset and mains hum.
Effect: they blame the ESP32. Add an AD8232 (or better, a digital AFE), battery power, and a notch or digital filter. The waveform appears.

Electrodes to AFE to ESP32 signal chain
ESP32 biosensor stack from electrodes through AFE to wireless dashboard

Easy to Interface: Plug-and-Play Modules

These have hobbyist boards that speak analog, I2C, or SPI to an ESP32 without a custom PCB.

  • ECG: AD8232 (analog out) or MAX30003 (SPI digital AFE).
  • EMG: MyoWare 2.0, Gravity Analog EMG, BioAmp EXG Pill (analog).
  • EEG: BioAmp EXG Pill for single-channel experiments; TGAM-class modules; ADS1299 for multi-channel SPI.
  • EOG: BioAmp EXG Pill, or AD8232 with filter parts retuned for slower eye signals.
  • EDA / GSR: Grove GSR and similar voltage-divider modules (analog).
  • PPG: MAX30102 / MAX30105 (I2C).

MyoWare 2.0 even has an official wireless shield with an ESP32-WROOM and a LiPo, built so the muscle sensor can run isolated from the wall (SparkFun, 2024). That pattern is the right mental model for the whole list: battery on the body, radio off the body.

Plug-and-play biosensor modules for ESP32 including AD8232 MyoWare and MAX30102

Advanced: Custom Front Ends

  • EGG: ultra-low-frequency filtering. AD620-class instrumentation amp or a carefully configured ADS1299.
  • BIA / ICG: AD5933 (I2C) or MAX30001 (SPI) to inject and measure AC safely.
  • ENG: high-gain amp (INA128 / ADS1299 class) plus a synchronized stimulator. Treat stimulus current as a safety design, not a GPIO hack.
  • ERG: EEG/EOG-like electronics, plus specialized electrodes and a timed light flash.

The ESP32 still fits. The bill of materials and the validation plan get longer.

Harder biosensors: EGG BIA ENG and ERG with specialized hardware

ESP32 Tips That Actually Matter

1. Treat the built-in ADC as a last resort

The ESP32 on-chip 12-bit ADC is convenient and imperfect: noise, non-linearity near 0 V and 3.3 V, and channel restrictions depending on Wi-Fi use (Espressif, 2023). For clean biopotentials, prefer:

  • ADS1115 (I2C, 16-bit) after an analog AFE such as AD8232.
  • Digital AFEs such as ADS1299 or MAX30003 that digitize on the sensor board and speak SPI.
Comparing ESP32 ADC, ADS1115, and ADS1299 for biosignal quality

2. Electrical safety is not optional

While electrodes touch a person, run the ESP32 from a battery (LiPo or pack). Stream over Wi-Fi or BLE. Do not leave USB connected to a wall charger or to a laptop that is itself on mains. SparkFun's MyoWare docs say the same thing in blunt language: remove the shield from the sensor when charging or programming, and do not charge while attached to a user (SparkFun, 2024). Open ADS1299 + ESP32 projects repeat the rule: battery on subject, USB disconnected (Asghar, 2024).

Problem: 50 Hz hum ruins every plot, and a fault path to mains is possible.
Cause: the subject and the wall share a ground through USB.
Effect: bad science and real shock risk. Battery + wireless fixes both.

Unsafe mains-powered electrodes versus safe battery and BLE setup

3. Sample at the rate the physiology needs

  • ECG: often 250 to 500 Hz for a useful waveform.
  • EMG (raw): often 500 Hz to 1 kHz+; envelope outputs can be slower.
  • EEG: often 250 to 500 Hz per channel, with serious attention to referencing.
  • EDA / EGG: low rates are fine; filter design matters more.
  • PPG: tens to a few hundred Hz, depending on the chip FIFO and your algorithm.

4. Filter in hardware first, then in software

AFEs already band-limit. Add digital notch (50/60 Hz), baseline wander removal, and, for EMG, envelope or RMS features. Do not expect a raw FFT on a noisy ADC pin to look like a textbook figure.

5. Label the project honestly

Breakout vendors and open BioAmp boards say it: research, education, prototyping. Not diagnosis, not treatment, not a cleared medical device (SparkFun, 2024; Texas Instruments, 2017). If you need clinical claims, you need clinical hardware, clinical process, and regulators.

A Practical Start Path

  1. Pick one signal. PPG or ECG for a first win. EEG if you already like signal processing.
  2. Buy a matched AFE module, not bare electrodes.
  3. Power the ESP32 from a LiPo whenever a person is connected.
  4. Read via I2C/SPI if you can; otherwise analog into ADS1115 or a quiet ADC1 pin with averaging.
  5. Stream over BLE or Wi-Fi to a phone or laptop for plots.
  6. Only then attempt EGG, BIA, ENG, or ERG, with datasheets and a safety plan open.
Five-step path to start ESP32 biosensor projects safely

Module Cheatsheet

ESP32 host map Signal Common module / IC Link to ESP32 DIY difficulty ECG AD8232, MAX30003 Analog / SPI Easy EMG MyoWare, BioAmp Analog Easy EEG / EOG BioAmp, ADS1299 Analog / SPI Medium EDA/GSR Grove GSR Analog Easy PPG MAX30102 / 30105 I2C Easiest BIA/ICG AD5933, MAX30001 I2C / SPI Hard EGG / ERG / ENG Custom AFE + extras SPI / Analog Hardest Shared rules: AFE in the middle, battery on body, wireless off body, and never claim clinical use from a maker module.

The alphabet soup (ECG, EEG, EMG, and the rest) is one family of body signals plus one optical cousin. The ESP32 is a capable wireless host for all of them. The product between the skin and the chip is what decides whether you learn physiology or fight noise. Start with PPG or ECG, keep the subject on battery power, and treat every plot as a lesson, not a diagnosis.

If you remember one line: electrodes never meet the ESP32 alone. An AFE, a battery, and a radio sit in between.

References