Friday, 5 July 2013

Minimal ECG using an Arduino and Xoscillo

First off, the picture :)

To display the wave I am using XOSCILLO, a very cool and open source tool (which I wrote :P) that converts your Arduino into an oscilloscope.

Circuit diagram

Here is the scheme, I am using the typical instrumental amplifier(ins amp) and then another op amp to get some more gain. An ins-amp is like an op-amps but with a huge CMRR, I am using a AD8221 which comes in a tiny small package, it's lead pitch is only 0.65mm, if you want to know what I did to create a simple breakout board please follow this link.

I'm using a single supply for the amps that comes from the arduino 5V pin, and I am creating a buffered virtual ground, this is really important.

Here is, a bit dark, a pic of the setup in the breadboard.

Tricks of the trade:

This is what makes the difference between a working ECG and a non working one :)

The main problem is that the device is so sensitive that it get interference from almost everywhere, specially the mains hum at 50hz). As you can see I got a clean signal, and I am not using any kind of serious filtering, note that xoscillo has a low pass filter and I am not even using it, so what are the tricks?

  1. Run it from a laptop and unplug the charger!
  2. Don't use a second monitor, the HDMI port will cause all sorts of high frequency interferences
  3. Get about 1 meter away from the laptop
  4. Buy some serious ECG electrodes, mines are "H124SG * Ø 24 mm", they come in a box of 50 and should cost about 11 euros. 

That's all, if you like it or build it or need help feel free to write a comment, it will encourage me to write more articles :)


  1. Hi, cool project. But I have a small remark to your schematic: As it's drawn, the 2nd OP does not add any gain at all.

    All the components around the LM324 in the upper right are completely insignificant compared to the impedance of the opamp inputs, it's just operating as a 1:1 voltage mirror (the leakage of the 10uF probably is likely enough so that there's no noticeable voltage shift).

    Also, instead of generating the 2.5V from the +5V supply voltage, you might be able to use the 1.1V stabilized reference of the ATMega on the analog reference pin (if you configure it right). It might be more stable than your Vcc supply (especially if you drive some additional loads).

    1. Will you please give full corrected figure?

  2. Doh! Good catch! Actually I made a mistake when I wrote down the circuit, thanks for pointing it out! I have just corrected it now.

    Good tip about using the 1.1V I'll give it a go.

    thank for your remarks!

  3. Can this be ported to run on a Raspberry Pi a computer/laptop isnt needed? The HDMI/Power issues will need resolving but a "TVcg" would be a powerful tool for "Doctors without Borders", etc.

  4. I am impressed my friend! Very clean signal. Props!

  5. Cool project. Good idea to state that you should unplug the charger - we don't want a physical connection to the power grid when not using medical grade equipment!

    And Raul CAD must be the most versatile CAD package I've ever seen :)

  6. are you having electrolyte imbalance issues? it appears your re-polarization phase is elongated. you might be calcium deficient.

  7. Thanks for the comments! This project ca be used with anything that has an ADC so a raspberry PI woudl be a good candidate too.

    TheVirus911, you mean the biphasic T wave? Yep I was told is technically abnormal and I may be getting a proper one to see what's up.. it could be that my ECG is distorting the signal somehow too.. thanks for pointing it out though!

  8. Very nice work !!! i'll try it soon :D

  9. This comment has been removed by the author.

  10. Nice rhythm, though you have a very pronounced T wave.

  11. Another cool project! Keep up the great work, I love reading this blog !

  12. Hi,
    as I understand, there are two filters: first is the high pass filter for 3.18 Hz, and second is the low pass for 49.8 Hz. Am I right?
    If yes, the question is: why in high pass filter the resistor and capacitor are connected in serial whereas in low pass they are connected parallel? And why 3.18Hz for high pass filter? I am new to electronics and I just found your website -it is great!

  13. Hi Raul,
    I'm trying to replicate your project but I have some problems...
    First of all I had to replace the AD8221 you wrote with an AMP04F either because I didn't find the part and because is much easier to plug in a breadboard (it's a DIP packaging!)
    Using your fantastic Xoscillo I can see only a lot of noise , as you can see here

    and nothing that seems like an ECG...
    To avoid external interferences I wrapped the breadboard with aluminium foil... but the result is the same...

    Thanks a lot for your time!

  14. Hello Raul,
    I have designed just like yours, I took ECG signal from an ECG simulator and used an Instrumentation amplifier AD620 ann filtered using low pass filter. Then I will convert the signal into a square wave by using an analog comparator. This wave will be provided to arduino uno R3 which count the beats (high) from the signal and displays heart rate per min on a LCD.
    Now I want to display the ECG signal on my PC through Arduino, Plz help me in this regard..


  15. This comment has been removed by the author.

  16. Simone,

    Sorry for the delay. Did you unplug your laptop from the mains? It should be running on the batteries. Are you sure your circuit is running as intended? I'd try to lower the gain lets see what happens too.

  17. Mehwish Iqbal,

    As for displaying the signal in oscillo you need to set the settings is xoscillo exactly as I did and you should see a curve. Use a low sampling rate that is the main thing.

  18. Hi Raul - this looks like a great project I want to try this weekend. Is the arduino source code availabe ?


  19. hello
    can I have the cording of this ecg project.I have stuck with it
    thank u

  20. This comment has been removed by the author.

  21. Hi, really cool project. I am trying to emulate your project and see what kind of output I get. Have you changed to circuit or values of the caps and resistors any further ? If so could you please update the new schematic or reply to this comment with details ? I would really appreciate it.

  22. Hi, really cool project. I was trying to emulate your project to see what kinda output I get but I couldn't get good results. I used the exact values for caps and resistors like you had in your schematic. I also used the exact same op amps and inst amps. Did you update the schematic any further ? I do not know what am I doing wrong.

  23. Will you please give final corrected circuit figure?

  24. Very nice article. I recommand it to my friends, visit here ALOKA UST-52101

  25. Very nice article. I recommand it to my friends,I,ll be back here

    again and again visit here
    ALOKA UST-5543

  26. thanks for this useful article,I,ll recommand it to my friends and I,ll be back again and again,Visit Our blog for more info.

  27. do u have anr code fr dis....if have plzz snd it

  28. do u have anr code fr dis....if have plzz snd it

  29. Very nice post, impressive. its quite different from other posts. Thanks for sharing.

  30. This comment has been removed by the author.

  31. Hello Raul,

    I just discovered this Minimal ECG project of yours.

    I have a question. In the pics with breadboard there are three sensor pads. On the schematic I can see two pads from the chest connected to the inputs + and - of the AD8221. The question is where is the third pad maked on the body as "REF" connected to in the schematic? There is a "REF" marked in the schematic, but I am not sure if that is the same "REF" on the body that does not have a line to show where it connects on the schematic.



    P.S. This is a repost of my last post as I do not seem to be able to edit it to correct what was not that bad typing. The site seemed to have moments of unannouonced interaction as I typed. Same challenges with unannounced interactions as I typed this PS after correcting the errors occurred as well. Opps, now the site shows I can delete my last post that had some typo errors that were a bit messy. I will delete so only this corrected post shows. John

  32. please give schematic and coding to

  33. Is the reference electrode, which is the third electrode, attached to the leg and is this electrode attached to the reference electrode in the circuit? What if we put him in a coke?