Arduino Display of Filtered ECG Signal

by zmeganculp in Circuits > Arduino

760 Views, 0 Favorites, 0 Comments

Arduino Display of Filtered ECG Signal

OSCILLISCOPE SIGNAL.jpg

An electrocardiogram (ECG) is an incredibly common and efficient diagnostic tool for detecting abnormalities in cardiac rhythms. The goal of this instructable is to create an ECG on a single breadboard to amplify and filter a human biosignal and display the resulting wave and heart rate using an Arduino.

Disclaimer: this device isn't a substitute for a professional diagnosis.

Supplies

  1. Breadboard
  2. LT Spice software (optional)
  3. Arduino Uno Rev3
  4. Associated Arduino software
  5. uA741 Op Amp x 5
  6. Oscilloscope
  7. Function Generator
  8. 9V D Cell Battery x 2
  9. DC Power Supply (used for earlier stages but not for human testing)
  10. 3 ECG leads and electrodes
  11. various wires (see images below)
  12. various resistors (see images below for values)
  13. various capacitors (see images below for values)
  14. various adapters

Instrumental Amplifier

Screenshot 2022-04-28 220803.png
INA SCHEM.png
LT SPICE INA.png

This stage is intended to amplify the signal received from the body to be interpreted. This specific circuit is set to have a gain of 2000 as expected voltages from the body are around 1mV. The LT Spice output showing this gain can be seen above. Any gain around 1000-2000 should work for this application, while keeping the output voltage below the threshold allowed by the 9 volt power source.

The intended design uses the values for resistors in the schematic, however, these could be substituted for similar values in case of supply shortages. For example, the end result was assembled using some substitutions i.e. R3 and R4 were 6.2k ohm resistors, R5 and R7 were two 100k ohm resistors in series, and R6 was a 4.7k ohm. All op-amps used were uA741.

Once the circuit is connected, it is a good idea to confirm the gain with an oscilloscope output and a small input signal from a function generator.

Notch Filter

NOTCH BREAD.png
NOTCH SCHEM.png
LT SPICE NOTCH.png

This next step creates a filter to cut out powerline interference at 60 Hz which could greatly affect the relatively small biosignal.

This filter needs to be more precise than the previous one as it does have to have a resonant frequency very close to 60 Hz. Nevertheless, slight changes in resistor values due to supply availability are still reasonable. Similar to in stage 1, some resistors were replaced. On the breadboard, R8 and R10 were both 330 ohm resistors in series with 1k ohm resistors, and R9 was a 33k ohm resistor in series with a 470k ohm resistor. For the capacitors, all capacitors in the schematic were 0.1uF(104) capacitors, with C3 being two in parallel. All op-amps used were uA741.

Low-Pass Filter

LOA BREAD.png
LOW SCHEME.png
LT SPICE LOW.png

This next step creates a filter to cut off all filters above a certain threshold, this can be seen in the LT Spice diagram above. Due to supply limitations slight changes to resistor and capacitor values from the schematic were used to construct the circuit. C1 in the schematic was a 47nF(473) capacitor and C2 was a 0.1uF(104) capacitor. R1 and R2 were both an 8.2k ohm resistor in series with a 15k ohm resistor to make an equivalent resistance of 23.2k ohms. All op-amps used were uA741.

Check-In!

LOW PASS VERIFICATION.png
NOTCH VERIFICATION.png

To confirm the validity of the functions of both filters, it is a good idea to confirm the outputs across a variety of frequencies. Magnitude plots for the notch and lowpass circuit components are included here, but simply confirming at a few frequencies is likely sufficient.

Electrodes and Biosignals - Bringing It All Together

FULL DESIGN.jpg
OSCILLISCOPE SIGNAL.jpg
LEAD 2 ECG.png

At this stage, all power supplies were replaced with two 9-volt batteries.

Electrodes were connected in a lead II configuration which should produce a signal similar to the image above. The left ankle connection is V1, the right wrist is V2 and the right ankle was attached to ground. The three circuit components were attached as seen above and the leads were connected to the input and ground connections. This signal was then output to an oscilloscope resulting in the image above.

Arduino Display

ARDUINO OUTPUT.png
ARDUINO BPM OUTPUT.png

The oscilloscope display from the previous step can be displayed on a computer along with a continuous heart rate display using an Arduino. The output from the circuit should be connected to pin A0, and a connection to ground should be made. To display the real-time ECG signal, the serial plotter tool on the Arduino software was used. The image on the left is the ECG output and the display on the right shows the BPM determined from QRS complex peaks. The code used to do this is included below.

CODE:

int UpperThreshold = 50; //Thresholding of where to read "beats" based on your signal input

int LowerThreshold = 90;

int reading = 0;

int BPM = 0;

bool IgnoreReading = false;

bool FirstPulseDetected = false;

unsigned long FirstPulseTime = 0;

unsigned long SecondPulseTime = 0;

unsigned long PulseInterval = 0;

void setup(){

Serial.begin(74880);

}

void loop(){

reading = analogRead(A0);

// Heart beat leading edge detected.

if(reading > UpperThreshold && IgnoreReading == false){

if(FirstPulseDetected == false){

FirstPulseTime = millis();

FirstPulseDetected = true;

}

else{

SecondPulseTime = millis();

PulseInterval = SecondPulseTime - FirstPulseTime;

FirstPulseTime = SecondPulseTime;

}

IgnoreReading = true;

}

// Heart beat trailing edge detected.

if(reading < LowerThreshold && reading > 2){

IgnoreReading = false;

}

BPM = (1.0/PulseInterval) * 60.0 * 1000;

//Serial.println(A0);

Serial.print("BPM = ");

Serial.println(BPM);

delayMicroseconds(3900);

{

// read the input on analog pin 0:

int sensorValue = analogRead(A0);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

float voltage = sensorValue;{

// read the input on analog pin 0:

//int sensorValue = analogRead(A0);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

// print out the value you read:

Serial.println(voltage);

};

// print out the value you read:

Serial.println(voltage);

}

}