Introduction: DIY ECG Using a Analog Discovery 2 and LabVIEW

About: I work as a Product Marketing Engineer at NI. In my free time, I love tinkering and finding creative ways to solve everyday problems.

In this Instructable, I will show you how to make a homemade electrocardiograph (ECG). The goal of this machine is to amplify, measure, and record the natural electrical potential created by the heart. An ECG can reveal a wealth of information about cardiac regulation, as well insights into pathological conditions. This DIY ECG project simplifies the circuitry by eliminating noise reduction components, accomplishing this by post-processing the data with LabVIEW.

Step 1: Materials


1) Analog Discovery 2 USB Oscilloscope

2) 2 OP482 Op Amp

3) 10 100 kΩ resistors

4) 7 10 kΩ resistors

5) 1 uF electrolytic capacitor

6) .1 uF ceramic capacitor (104M)

5) 6 diodes (50V General Purpose Rectifiers 1N4001)

6) Breadboard(I use an Explorer Board)

7) DIN ECG snap leads or alligator clips

8) 3 Surface electrodes or 3 pennies(lotion needed if pennies are used)

(Everything except 1,7 and 8 is included in the Analog Parts Kit)


1) WaveForms version 2.6.2 or later

2) LabVIEW (Download & install the free, 45-day evaluation)

Step 2: Circuit Setup

    Above you can see my circuit setup(and the Fritzing drawing) as well as the schematic that I used to build it. I also have an op amp schematic specifying what each part of the circuit is doing.

    The 200k resistor can be built by using two 100k resistors in series(one next to another). Diodes across every input to decrease the risk of shock. By doing this, the maximum voltage across any two electrodes will be .7V. This is much higher than the heart signal, so it won't affect any other performance.

    Step 3: Analog Discovery 2

    1. Connect the Scope Ch. 1 negative(1- orange wire white stripe) to its ground(downward arrow black wire)
    2. Connect the Scope Ch. 1 positive(1+ orange wire) to the voltage output of the circuit
    3. V- power supply(V- white wire) goes to the negative voltage hub
    4. V+ power supply(V+ red wire) goes to the positive voltage hub

    Step 4: DIY Electrodes

    Electrodes can be bought online or can be made at home. This step is only required if you choose to build your own electrodes. It is important to keep in mind that homemade electrodes won't give you the same signal clarity. While you can make electrodes from anything conductive I recommend using pennies (since they are cheap and readily available). You can either solder the wire directly to the penny, or you can use a gator clip like I did. A dot of moisturizing lotion applied to the pennies can be used to improve conduction between the pennies and the skin. Finally, use electrical tape(or scotch tape) to hold the pennies firmly to your body in the positions that shown in the next step.

    If you were able to buy I recommend buying surface electrodes, you could use the gator clip instead of the snap leads.

    Step 5: Placing Electrodes

    Electrodes can be placed in 2 different ways

    Option 1

    Place a ground electrode on the right side of your chest, then place the negative electrode in line with it on the opposite side of your chest. Finally, place the positive electrode stomach in line with the negative electrode.

    Option 2

    Place a ground electrode on the inside of your left wrist, then place the positive electrode on the inside of your left ankle. Finally, place the negative electrode on the inside of your right wrist. Option 2 generally has more noise and a weaker signal but it is the better option if chest hair makes option 1 difficult.

    Step 6: WaveForms

    1. Open WaveForms, Select Analog Discovery 2 in the device manager
    2. Select the Supply(WaveForms 2015) or the Voltage(WaveForms 2014)
    3. Set VP+ tp 5V and VP- to -5V and select the power button to turn the power on
    4. Next, select "Scope" in the main WaveForms menu
    5. On the right side, you will see the "time" settings, set Pos to 0 and Base to 500 ms/div
    6. Below the time setting is the "C1" settings, set the Offset to 0V and set the Range 200 mV/div
    7. Select the "Run" button above the graph

    You should now see an output similar to the one in the picture above, variation in the location of electrodes will vary the shape of the ECG. If your ECG appears upside-down, reverse the leads! Make sure to exit out of Waveforms before you move onto the next step.

    Step 7: LabVIEW Code

    First, download the LabVIEW file "" below if you are placing the electrodes on your torso or download "" if you are placing them on your wrist and ankle. Make sure your Analog Discovery 2 is connected via USB and open the program. Once you have opened the program, you should see "Analog Discovery 2" as the device name and "mso/1" as the analog channel in the "Analog Discovery MSO Settings". Also, make sure that the "Master Enable" is switched on in the "Analog Discovery 2 Power Supplies" and the Toggle voltage supplies are set to positive and negative 5V. Once the circuit and electrodes are hooked up correctly, you can start the program.

    You will see five graphs; the first graph shows the unfiltered signal, but each graph has a different filter that is used to minimize noise. The second graph takes the average of a certain number of points; you can increase or decrease the number of samples to average. The Third graph uses the previous filter and a bandpass filter while the fourth also uses a bandstop filter. The lower and upper cutoffs for can be adjusted but be careful not to filter too much or you will lose important parts of the signal. Finally, the final graph uses a smoothing filter to eliminate the remaining noise.

    This program is also set up to detect your heart rate; it does this by identifying the number of peaks(each peak represents a heartbeat). Once you have your graphs looking the way you want to you can click the "on" switch in the "Heart Rate" section. Make sure that the HT(high threshold) and LT(low threshold) are adjusted so that the peak of each heartbeat is above them both and the rest of the signal is below the lower threshold.

    Step 8: LabVIEW - Simple Version

    This is the simplified version of my program, It only has the final ECG and the rate calculations. Please be extremely careful when building this circuit and when using this ECG in general. Do not try and use power from a wall socket or make changes to the circuit without knowing what you are doing. If you have any questions or concerns, please comment below and I will answer promptly. Thank you for reading!!

    Makerspace Contest

    Participated in the
    Makerspace Contest