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 :)



23 comments:

Christian Vogel said...

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).

http://goo.gl/eVg7o

Raul said...

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!

Shiraz Kanga said...

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.

swharden said...

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

Rob said...

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 :)

TheVirus911 said...

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

Raul said...

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!




Gontran Sion said...

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

Jake said...
This comment has been removed by the author.
Jake said...

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

Martiz said...

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

Wieczorki Naukowe said...

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!

Enal said...

how to use the Xoscillo

Simone Nanni said...

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

https://docs.google.com/file/d/0B43ENY9K5_IvZmFSLVB1aFRBbVk/edit?usp=sharing

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!
Simone

Mehwish Iqbal said...

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..

Thanks

Mehwish Iqbal said...
This comment has been removed by the author.
Raul said...

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.

Raul said...

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.

Techno said...

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

Thanks

Dilhani Dissanayake said...

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

Dilhani Dissanayake said...
This comment has been removed by the author.
Arefin said...

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.

Arefin said...

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.