DIY ECG Heart Monitor | Analog Interface + Arduino

by mcmchris in Circuits > Sensors

3162 Views, 2 Favorites, 0 Comments

DIY ECG Heart Monitor | Analog Interface + Arduino

ECG.jpg

Hello to everyone, today I am here to show you a very insteresting project that I was working on for a while, it consists on a DIY Electrocardiograph (ECG) that extracts data directly from your heart electrical impulses with some electrodes (from your preferred lead) and a reference right leg driver. It uses several stages to filter the heart signal:

  1. Instrumentation amplifier.
  2. High Pass Filter (@0.1Hz)
  3. Low Pass Filter (@160Hz)
  4. Notch Filter (@60Hz)
  5. Level Shifter (offset: 1.6v dc)

I am using the ESP32 to process the signal, the code spend a while analysing the signal to find the largest peak to make the noise of life 😂, then calculates the time between 10 pulses to average the BPM (the code could be modified to perform better).

Here I leave you a tutorial with all the information so you can make your own version.If you are a visual learner I know that a video worth more than 1000 words, so here is a Tutorial video. (I am a Spanish speaker, so please consider turning on English subtitles):

Skills Required

Screenshot (237).png
Screenshot (222).png
Screenshot 2021-05-17 160243.png

This project may seem difficult or very complex, but it is definitely not completely, since you will have all the guidance for the construction, it was difficult for me to design it to make life a little easier for you. Any conceptual doubt, you are free to ask it without problems.

You should have understandings on:

  1. Analog electronics.
  2. Arduino programming
  3. Circuit making.
  4. PCB design (optional)

The PCB design attached in the project is SMD, nevertheless, you can make your equivalent version using the diagram in TH devices.

Components and Parts List

Screenshot (228).png
Screenshot (212).png
Screenshot (219).png
Screenshot (216).png
Screenshot (215).png

The Electronics discrete components as resistors and transistors will be attached in a BOM file attached here.

🛒Materials:

Circuit Diagram and Schematic

Schematic_ECGFilter_2021-05-17.png

Here is the Circuit Diagram of our project:

It has all the internal conections of the circuit that will us allow to create the PCB design later.

I also attached the PDF of the Schematics so you can see it better.

PCB Design and Ordering

Screenshot 2021-05-17 160243.png
Screenshot 2021-05-17 160407.png
Screenshot 2021-05-17 160509.png
Screenshot (213).png
Screenshot (212).png
Screenshot (214).png

For the implementation of a good project we need a reliable assembly for the circuit that makes it up, and there is no better way to do it than with a good PCB.

Here you can download for FREE the Gerber, BOM and Pick & Place Files, the ones you need to order your PCB on your PCB manufacturing company.

I suggest JLCPCB:

$2 for 1-4 Layer PCBs⚡, Get SMT Coupons🎫

Assambling the Whole Project

Screenshot (217).png
Screenshot (218).png
Screenshot (220).png
Screenshot (221).png

In my first attempt of the project I missed the Right Leg Driver stage in the circuit, because of that I got obligated to assamble it on a protoboard, nevertheless, the files an diagrams attached in the project are already corrected and fixed, also the PCB has the missing components and parts.

Because of that, you may ignore the mess of jumping wires and audio jacks.

  1. You just need to power up the circuit with +5V and GND.
  2. Connect an active buzzer to a digital output pin of your microcontroller.
  3. Connect the signal output of the circuit to an analog input of the microcontroller.

And let's jump to the code.

Connect the Electrodes

AD8232-Electrode-Placement-1.jpg
Screenshot (230).png
Screenshot (229).png
Screenshot (231).png
Screenshot (232).png

There are many leads where you can connect the electrodes but I show you the lead I did.

As nearest you place the electrodes to your heart, you will have a greater amplitude output signal.

If you don't want to place them in your chest, you can do it in your arms directly. (Play with different positions to find the best).

Electrodes are really sticky and the adhesive can dry your skin, nothing lethal 😉.

Code and Programming the ESP32 Microcontroller

Screenshot (224).png
Screenshot (225).png
Screenshot (226).png
Screenshot (223).png

Download the CODE here for FREE (just insert 0 in the charge box).

After you have opened the code in your Arduino IDE verify:

  1. Select your board, in my case the Feather ESP32.
  2. Connect the board by USB to your PC.
  3. Select the Port that appears on your IDE.
  4. Verify your code compiles.
  5. Upload the code.

A little explanation:

The code let the microcontroller to scan the input ECG signal and find the lowest peak and it's value (typical the R part of the ECG signal), then based on this ADC value, ask repetitively if the ADC sees a peak like the one learned before, then make a sound and average 10 pulses to return the BPM in the serial monitor.

Testing and Verifying That You Are Alive

Screenshot (234).png
Screenshot (235).png
Screenshot (241).png
Screenshot (238).png
Screenshot (239).png

Once you have placed your electrodes, turn on the system by connecting the USB cable to your board and let it scan the signal, then your buzzer should start sounding.

If you have an oscilloscope, please verify the integrity of the signal, if it presents a lot of noise try adjusting the notch filter frequency and the gain.

Reset the microcontroller so it can learns the new and corrected signal. Enjoy the project, you can attach an LCD to print the BPM and a matrix screen to plot the ECG graph.

PD: To get a cleaner and nice signal don't be barefoot, do not touch walls of your house and a nice trick is to touch a gnd cable of your circuit and it gets even better (this is the right leg driver job but just tested and works).