Building an ECG With Breadboard Components and Arduino

by chill1919 in Circuits > Arduino

610 Views, 0 Favorites, 0 Comments

Building an ECG With Breadboard Components and Arduino

BME 305 Final Circuit.jpg
ECG Signal.jpg
Arduino ECG Signal.png

This design should help amplify and filter out a signal from a human subject and show the ECG signal and heart rate.

Supplies

The following supplies will be needed:

  • x5 - LM741 op amps or equivalent
  • breadboard capable of fitting 5 op amps with some extra space
  • numerous wires that can be used on the breadboard
  • x2 - 9 V batteries or equivalent power supply (can also use 15 V DC power supply) for op amps
  • oscilloscope w/ necessary cables
  • function generator w/ necessary cables
  • Excel
  • 2x - 18 kOhm resistor
  • 2x - 220 kOhm resistor
  • 2x - 12 kOhm resistor
  • 3x - 470 kOhm resistor
  • 2x - 1.5 kOhm resistor
  • 1x - 27 kOhm resistor
  • 1x - .2 uF capacitor
  • 2x - .1 uF capacitor
  • 1x - 33 nF capacitor
  • 1x - 68 nF capacitor
  • Arduino
  • ECG electrodes

Amplifier

LTSpice Amplifier.png
Amplifier Project.jpg

Create the amplifying circuit using the image above. There is also an image of the circuit from LTSpice for further clarification if needed. It will likely be easier to use the + and - rails on the top and bottom of the breadboard to supply power to all of the op amps. The same goes for using one of those as a ground. In the example circuit, the top positive rail was used as the positive power supply, while the bottom negative rail was used as the negative power supply. The positive rail on the bottom was used as a ground.

Supplies for this step:

  • 1x - 18 kOhm resistor
  • 2x - 220 kOhm resistor
  • 2x - 12 kOhm resistor
  • 2x - 470 kOhm resistor
  • x2 - 9 V batteries or equivalent power supply (can also use 15 V DC power supply) for op amps
  • wires
  • x3 op amps

Test Amplifier

Using your function generator, supply the circuit with a sinusoidal wave of around 1 V amplitude. Then, use your oscilloscope to compare the input voltage from the function generator and the output voltage from the circuit. The gain should be around 1000, but if it is a bit off it should be fine.

Notch Filter

Notch Filter Project 304.jpg
Notch Filter Schematic.png

Recreate the LTSpice schematic for a Notch Filter on your breadboard. An example of what this should look like is provided. In the example circuit, the top positive rail was used as the positive power supply, while the bottom negative rail was used as the negative power supply. The positive rail on the bottom was used as a ground.

Supplies for this step:

  • 1x - .2 uF capacitor
  • 2x - .1 uF capacitor
  • 2x - 1.5 kOhm resistor
  • 1x - 470 kOhm resistor
  • x2 - 9 V batteries or equivalent power supply (can also use 15 V DC power supply) for op amps
  • wires
  • op amp

Test Notch Filter

Notch Filter Test.png

In this step, you may test the Notch Filter to make sure it is successful in getting rid of noise around 60 Hz. To do this, create a frequency response plot. This requires you to use the function generator and oscilloscope. Set the function generator to input a sinusoidal wave to the Notch filter (don't attach the amplifier yet) with an amplitude of 1V and a frequency of 10 Hz. Record the input amplitude, output amplitude, and the frequency you used and input those value into Excel for later graphing. Repeat this by increasing the frequency by 10 until you reach 50 Hz. After reaching 50 Hz, increase in steps of 1 Hz until you reach 70 Hz. After that, you can increase in steps of 10 again until you reach 100 Hz. Then, plot the frequency on the x-axis and the output amplitude divided by the input magnitude on the y-axis. Make the x-axis logarithmic. This graph should show the Notch Filter filtering out frequencies around 60 Hz. I should look similar to the v-shaped part of the image shown.

Supplies Needed:

  • circuit
  • oscilloscope w/ necessary cables
  • function generator

Low Pass Filter

Low Pass Filter Project.jpg
Low Pass Filter Schematic.png

Recreate the LTSpice schematic for a low pass filter on your breadboard. An example of what this should look like is provided. In the example circuit, the top positive rail was used as the positive power supply, while the bottom negative rail was used as the negative power supply. The positive rail on the bottom was used as a ground.

Supplies:

  • 18 kOhm resistor
  • 27 kOhm resistor
  • 33 nF capacitor
  • 68 nF capacitor
  • wires
  • op amp

Test Low Pass Filter

Low Pass Test.png

To test the low pass filter, you must recreate what you did for the Notch filter. However, for this test start at 50 Hz, go up in increments of 10 Hz until 130 Hz. Go up by increments of 5 Hz until 145 Hz. Then go up in increments of 1 Hz until 170 Hz. After that, go up by 5 Hz until 200 Hz. Then, you may continue gathering data, but it may not be needed. Make sure to get the input voltage, output voltage, and frequency at each step and record it in Excel. Then, plot the frequency on the x-axis and the output amplitude divided by the input magnitude on the y-axis. Make the x-axis logarithmic. This graph should show that the magnitude (output amplitude / input amplitude) is equal around .7 near 150 Hz which is what the low pass filter cutoff frequency should be. However, this number may vary a bit and as long as it doesn't stray too far from 150 Hz, it should be fine. It should look similar to the top curve in the image shown.

Supplies Needed:

  • circuit
  • oscilloscope w/ necessary cables
  • function generator

Attach All 3 Stages

BME 305 Final Circuit.jpg

Attach the output of the amplifier to where the input of the Notch filter should be. Then attached the output of the Notch filter to where the input of the low pass filter should be. The circuit should now be fully connected. An example circuit is shown in the image.

Test With Simulated ECG or Human Subject

ECG Output.jpg

Now, attached the 3 electrodes to the human subject as follows: the electrode that connects to the ground on the circuit should be attached to one of the ankles of the subject, and the other two electrodes should be connected to the two wrists of the subject. The electrodes connected to the wrists of the subject should be connected as the two inputs to the circuit (the inputs of the first two op amps). Depending on the orientation of the ECG output, you may have to switch which electrode is attached to which op amp input. Then, connect the output of the whole circuit (which should be located by the low pass filter) to the oscilloscope. Then image shown above should look similar to the output you get.

Arduino Code

Use the following code for your Arduino or code it yourself:

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

int LowerThreshold = 60;

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(9600);

    }

 

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;{


  // print out the value you read:

  Serial.println(voltage);

};

  // print out the value you read:

  Serial.println(voltage);

}

    }

Supplies Needed:

  • Arduino


Test Arduino Code

Arduino Simulation.png
Arduino BPM.png

Connect the function generator directly to the Arduino to test the code. For our Arduino, we attached the positive (red) wire to the zero node and the negative/ground (black) wire to the ground node of the Arduino. Then set the function generator to send a 1 V amplitude signal with 1 Hz frequency. The waveform should be a simulated heartbeat/ECG signal. The plot and BPM readings should look similar to the images used.

Human Subject With Arduino Code

Arduino Human.png
Arduino Human BPM.png

For the last step, there may be some issues using the Arduino with the circuit. Sometimes, the final graph may not show up, due to there being no way keep the signal from going above the 0 line that is the minimum on the Arduino graphs. Therefore, it may be better to use the oscilloscope if the signal is not showing up.

Attach the output of the circuit to node zero of the Arduino and attach a ground to the ground node. Then attach the ECG to the human subject as mentioned before. The reading by the Arduino should look like the images provided.