Designing a Functional ECG With Arduino Output
by jcvanars in Circuits > Electronics
533 Views, 2 Favorites, 0 Comments
Designing a Functional ECG With Arduino Output


According to the Center for Disease Control and Prevention (CDC), heart disease is the leading cause of death for men, women, and most racial and ethnic groups across the United States. In addition, cardiovascular disease is responsible for roughly 19 million deaths per year worldwide, and that number is only expected to increase in the coming years. It is for this reason that we need devices capable of quickly and easily monitoring the heart’s activity and efficacy. An electrocardiogram (ECG) is a quick, painless, and non-invasive way to monitor electrical signals moving through the heart and display them as waveforms. Specifically, it shows electrical differences across the heart as depolarization and repolarization occur across the atrial and ventricular heart sections during each cardiac cycle (heartbeat). ECGs are commonly employed to help in diagnosing heart problems such as arrhythmias, coronary artery diseases like atherosclerosis, myocardial infarction (heart attack), or heart palpitations, but is also used to ensure that cardiac treatments that are already in place such as pacemakers are working properly.
ECGs have many different components including electrodes to gather electrical input as well as an amplifier to make that input easier to read and display on the output waveforms. Toward that effect, the device constructed throughout this tutorial includes an instrumentation amplifier (INA) to amplify input signal. However, ECGs are subject to many artifacts appearing in the signal and distorting the output waveforms. These can come from wall outlet signals and patient movement and can cause the ECG to be inaccurate. To minimize these artifacts, the ECG designed and constructed below features a low pass filter that will prevent unwanted high frequency signals from displaying and a notch pass filter that is specifically designed to cut off the frequency of the wall outlet signal so no artifact or distortion will display on the output.
Supplies
- Breadboard
- Arduino
- USB Cable
- Computer capable of connecting to the Arduino via USB
- Collection of jumper wires (20+)
- 9V battery or Agilent E3613A DC power supply
- 5 LM741 or UA741 op-amps
- 1 1k Ohm resistor
- 2 1.3k Ohm resistors
- 2 4.7k Ohm resistors
- 3 16k Ohm resistors
- 1 22k Ohm resistor
- 1 33k Ohm resistor
- 2 150k Ohm resistors
- 1 510k Ohm resistor
- 1 0.033 uF capacitor
- 1 0.068 uF capacitor
- 1 0.22 uF capacitor
- 2 0.1 uF capaitors
LTSpice Simulation - Instrumentation Amplifier (INA)



In order to test the efficacy of the three individual circuit components before using the time and resources to actually build them, you should use a simulation program such as LTSpice to simulate the circuits with the values calculated for each component and run test signals through each to determine if they were working properly as intended and would work if built on a breadboard.
As previously stated, the INA is used to amplify the relatively low signal input received from the electrodes placed on the patient. In this case, our goal is to construct an INA with a gain of roughly 1000. This means that any signal put into the INA will be output at 1000 times the input magnitude. The left side of the equation above becomes 1000 because this is the gain value that we want for our amplifier. In addition, R1 is a fairly arbitrary value and therefore we set it to 1000 as well. From this, we know that the two quantities on the right side of the equation should be as close to each other in value as possible, to allow for as little variance in the final circuit as possible. Thus, by taking the square root of 1000, we learn that we want both of these quantities to be as close to 31.6 as we can get them, while still using values for R that coincide with available resistors. My circuit diagram is shown above, but feel free to do the calculations for yourself to coincide with whatever resistors you have access to!
Lastly, we have to test this simulated circuit to ensure the amplification actually works. We do this by sending in an arbitrary sine wave with a known amplitude, like 1 mV, into one input of our circuit and grounding the other. We know our simulated circuit works if we see a 1000 times amplification in the output.
LTSpice Simulation: Notch Filter



We need the notch filter in our ECG in order to ensure we do not receive artifacts from the outlet we are using to power our machine. Wall outlets in the United States have a highly stable 60 Hz signal, so this is the frequency we want to cut out of our ECG output. My circuit diagram is provided above but if you want to calculate components for yourself, the equations to do so are also above. Running an AC sweep from 1-100 Hz on our simulated circuit provides us with a magnitude response plot to see what the output signal looks like at given frequencies. The goal here is to see a very sharp decline in signal, to near zero, at 60 Hz. An example from my circuit is also provided.
LTSpice Simulation - Low Pass Filter



The last part of our circuit we need to simulate is the low pass filter. This portion of the circuit is used to cut out frequencies higher than those of the signal we want to measure, the heart’s activity. With this in mind, we chose a cutoff frequency of 150 Hz. My circuit diagram as well as the equations and values needed to calculate the components for yourself are provided above. Testing this filter is similar to the notch filter as we need to run an AC sweep on this one as well. From this, to determine if the low pass is working as intended, we take our output curve’s maximum voltage, Vmax, and divide it by √2. Doing so we get 0.701 V. It is at this voltage that our cutoff frequency should be present on the curve.
Building on the Breadboard & Testing






Now that we know each component works in theory and simulation, we have to physically construct them and test them individually with real, non-ideal resistors, capacitors, and signals. We will also test all three components separately using the same methodology as the LTSpice simulations to ensure they are constructed correctly before we integrate them into the final, complete circuit. Before we start building, one of the most important components of our circuits are the op-amps, therefore it's crucial we understand how to properly wire an op-amp into our circuit. A map of the op-amps leads and what they correspond to can be found above. Also, it should be noted for the sake of neat circuitry and ease of construction, we use the entire positive left column of the breadboard as the negative voltage source for the op-amps and the entire positive right column of the breadboard as the positive voltage source for the op-amps. This allows us to only use one source for all five op-amps we will be using for our ECG. We will also be using the entire negative left column as the ground for our entire circuit.
Now, using the LTSpice diagrams as a guideline, we constructed the three individual circuits on the breadboard and tested them one at a time. The INA should be built first, then the notch filter, then the low pass, as this is the order the final circuit will be integrated in. The individual circuits can be seen above. In addition, test results performed on each circuit to affirm they worked individually are present above.
Integration of Circuits


Now that each circuit is constructed and confirmed to work individually, we must integrate them all together to create our final circuit. To do this, we connect the output of the INA to the input of the notch filter, and the output of the notch filter to the input of the low pass filter. Now we also have to test the fully integrated circuit to ensure that everything is properly wired and connected and works together as intended. We can do this two ways. Firstly, we send an arbitrary cardiac signal from the Agilent function generator into the completed circuit and compare the input and output on the oscilloscope. Secondly, we attempt to test the circuit with a real cardiac signal from a volunteer. We used the function generator for our test.
Arduino



Since we know that our integrated circuit works, the last step is to use an Arduino and program it to output the ECG waveforms and a beats per minute (BPM) reading when receiving input from our circuit. In addition, we are also going to use our BPM reading to flash an LED light every time we detect a heartbeat. As a quick overview, we must connect our Arduino to our circuit using jumper wires, one ground wire into the Arduino’s GND analog pin and another wire from our integrated circuit’s output to a chosen analog pin on the Arduino, in this case we use pin A0. Lastly, we place the LED on the digital side of the Arduino, with the positive, longer leg in the A13 pin and the negative, shorter leg into the GND pin next to it. Now we use the Arduino software to program the Arduino to display the ECG waveforms, light the LED with each heartbeat, and read and calculate the BPM. A brief walkthrough of the code is provided.
Arduino Results



Above is the serial plotter display from our Arduino code. This output aligns with what we want from our ECG waveform and with the previous tests’ results. The blue waveform is the ECG, while the green line represents the BPM. This BPM reading is better observed in the serial monitor option of the Arduino, the output of which is present above as well. Our BPM reading stays consistently around 70-73 BPM, this is consistent with the 1.2 Hz cardiac signal we were supplying to our circuit. Also pictured is the LED light programmed to flash with each detected heartbeat.
And that's all! Enjoy your new ECG and thanks for building alongside us!