This ECG (Electrocardiogram) unit has an integrated display. The display can show individual heart beats in a large format, the train of heart beats in a small format and a Poincaré plot.
It is battery powered and can be worn round your neck on a lanyard.
It is built from an AD8232 module (£7 with leads), an Arduino Nano (£3) and a 2.8″ TFT display (£6) plus a few resistors, a pushbutton and so on – the sort of things you already have. For power, you can use 4 AA cells or a single Lithium cell.
You might be interested in your heart during the Covid-19 pandemic. Covid-19 can sometimes give rise to cardiac complications including arrhythmia, ischaemia, infarction, tachycardia and conduction problems. But by the time that happens, you’re probably lying in an intensive care ward.
Step 1: Safety and Medical Disclaimer
Here’s some legal blurb and a discussion of electrical safety. The most important point is do not operate the circuit when it’s plugged into a PC which is plugged into the mains. Oh yes – and don’t blame me if you kill yourself.
I am not a medical professional. This Instructable was created for information purposes only. It does not describe a medical device. The information given here is not intended to be a substitute for professional medical advice. If you think you have a medical condition you should contact a qualified health professional. If you think you have a medical emergency you should contact your local emergency services. The device described here is not a substitute for professional medical diagnosis, ECG interpretation or treatment. You are encouraged to confirm any information in this Instructable.
As I have no control over how you build the electronics described here, I cannot guarantee its safety as a medical device. I think it is perfectly safe for me to use but you should make up your own mind. It’s running off 4 AA cells or a single Lithium cell for goodness sake – how dangerous can it be?
If you have been fitted with an internal defibrillator or pacemaker, do not attach electrodes to your body and mess about with circuits.
Professional medical electronics should conform to IEC 60601. I have designed medical electronics in the past but it was a few years ago. I seem to have lost my copy of IEC60601 which is annoying as you have to pay for it. Would this device get IEC 60601 approval? How safe is it?
IEC 60601 is a huge document. The most interesting questions to an electronics designer are:
- how much current can I pass through the patient?
- what electrical isolation is required?
- what happens if a “component” fails?
- how much electromagnetic interference can I produce?
- what about a defibrillator?
How much current can I pass through the patient? In “Normal Working” operation the current limit is 100uA a.c. and 10uA d.c. and in single fault condition it is 500uA a.c. and 50uA d.c. This circuit would be classed as an “Applied Part”.
I don’t know what circuit the manufacturer of the AD8232 module has used. When I examine the one I have, it appears to be one of the circuits in the “Application Circuits” section of the AD8232 datasheet.
The input impedance of the chip pins is 10Gohm so the “Normal Working” operation the current is under 1nA.
The electrodes are connected to the chip through 180k resistors. The chip operates at 3.3V so if the chip goes wrong, the maximum current is 3.3/180k = 18uA.
So the chip and its circuit is safe so long as it’s battery operated.
What electrical isolation is required? An “Applied Part” has to be double isolated at 4000VAC. Your desktop PC is not electrically isolated to that degree therefore you should never operate the circuit when it’s plugged into a PC which is plugged into the mains. A standard PC power supply almost certainly does not comply with the electrical IEC 60601-1 requirements from several standpoints, e.g. leakage current, dielectric strength.
Can you operate it when it’s plugged into a PC which is running on batteries? It wouldn’t be allowed for a medical device but for a domestic device it probably would be allowed. (Domestic regulations are less stringent.)
Did I operate it when plugged into a PC which was plugged into the mains? I’m not saying. I’ve been using desktop PCs for decades and have never got a shock off one. I’m just telling you that you shouldn’t do it.
Would the circuit’s isolation conform to IEC 60601? If it were battery operated then that’s one layer of isolation. Where’s the second layer? I guess maybe you’d need two insulated boxes one inside another. IEC 60601 sometimes seems a little silly.
The circuit should have no exposed conductive surfaces that are connected to the electronics. You have to worry about electrostatic discharge: what it the patient rubs a balloon on their hair then touches the box?
The patient shouldn’t be able to touch the electronics or the battery or whatever. Yes, I know you’ve never got a shock off a 6V battery – I’m just telling you the regulations.
Electrical isolation also depends on the creepage distances on the PCB and air clearances. The AD8232 module uses 0603 resistors on its input. An 0603 doesn’t have sufficient creepage.
Is the electrode connector suitable? No way. It’s a 3.5mm stereo jack plug. You could tape the electrodes to your chest then poke the jack plug into a mains outlet. I don’t know why you’d want to but you could – right?
What happens if a “component” fails? IEC 60601 says that the device must remain safe under a ‘single fault condition’. A medical device must operate safely not only in normal conditions, but also in abnormal and single fault conditions. The standard does not require that the medical device remains safe with two or more independent faults. A “fault” is typically a component failure.
What counts as a “component”? I have no idea. You could go through each of the electronic components and say “what happens if this goes short-circuit?” and “what happens if this goes open-circuit?”. Is the PCB a “component”? How can it fail? Can it suddenly re-arrange itself and connect battery to two electrodes? I can’t find a definition of a “component” or “fault”.
If it’s battery operated and a “component” is an electronic component like a resistor or an IC then the circuit is safe.
How much electromagnetic interference can I produce?EMC is a big problem when designing medical equipment. Hospitals are full of electronic stuff that people’s lives depend on so the EMC requirements for medical equipment are a lot tougher than for domestic electronics.
I have no idea how much EMC the board produces. The biggest culprit is probably the Arduino. I’ve never had an Arduino interfere with a TV or cellphone but I suppose it might.
In theory, you should put the circuit in a Faraday cage and worry about what wires go in and out. In practice, I don’t suppose you’ve ever thought about EMC when you build an Arduino circuit, have you?
What about a defibrillator? So you’ve built your medical electronics and done the safety analysis and then IEC 60601 has one more surprise for you. Your circuit has to survive a defibrillator.
What is the standard for a defibrillator? I couldn’t find one. Each manufacturer decides for themselves and the physician can decide what to apply. Shall we guess a capacitor charged to 300V containing 300 joules? That’s connected to your chest somewhere near the ECG electrodes. I suspect that will fry the circuit. IEC 60601 says that the device must remain safe – it doesn’t say that it has to continue to work.
A proper medical ECG can survive a defibrillator and go on working. Normally, you would have some protection diodes on the connections to the electrodes. The AD8232 module doesn’t have them.
The bottom line is: you could make this circuit into a medical device that would conform to IEC 60601 but it would be a lot of work and testing and certification would be a huge expense. This is just a circuit you’re building for fun.
See here and here for discussions of the dangers of a small battery. I have measured the resistance between the electrodes as 150k so, in the worst case, a 6V battery gives a 40uA current – well below the milliamps needed for a battery to be dangerous.
Step 2: AD8232 Module
The AD8232 chip contains a high quality, low noise instrumentation amplifier and signal conditioning to remove noise. It is intended primarily for recording ECG and takes a lot of the hard work out of designing a system.
Buy a module like the one in the photo. Search eBay for “AD8232 module” or “ecg module”. For convenience, get one with leads and electrode pads.
Connect it to an Arduino Nano (or Uno or Mini with a 16MHz 328P) as shown above. I used a solderless breadboard.
The AD8232 includes “leads off detection”. If either lead is disconnected, the LO+ or LO- pins of the module go high. For initial testing, I connected the LO+ and LO- pins to two LEDs though 1k resistors to ground. The LEDs light when a lead is disconnected. For the final circuit, remove the LEDs and connect LO+ and LO- to the Arduino. Don’t leave the LEDs connected – the AD8232 pins won’t go high enough for the Arduino inputs to register HIGH.
Download the ArdECG0.ino sketch and upload it to the Nano. Connect the Nano to a PC running on batteries. In the Arduino IDE, select the Tools|SerialPlotter menu command. Set the baud to 57600.
With the module I bought, the electrode leads are coloured:
- LA Left Arm: Green
- RA Right Arm: Red RL
- Right Leg: Yellow
Yours may be coloured differently. Which lead is which? try touching the leads together:
- Non touching: both LEDs lit
- LA touching RA: both LEDs lit
- LA touching RL: LO+ LED is off
- RA touching RL: RO- LED is off
My module came with only 3 sticky electrodes. They’ll get used up quickly so I decided to make my own. I happened to have some of the popper connectors left over from another project. I used tinplate for the electrodes themselves. Copper coins work as well but tarnish more quickly and stain your skin. As electrode jelly, I mixed thick shampoo and salt. I stuck them onto my chest with masking tape – it would last a few hours.
Attach the electrodes as shown in the picture above.
- LA to the left side of your chest below the clavicle (collar bone)
- RA to the right side of your chest below the clavicle
- RL somewhere low down away from the heart
The RL electrode is called “Right Leg” but it doesn’t actually need to be on your leg. It’s a reference electrodethat reduces common-mode interference. Anywhere well below and away from your heart is fine. The lower-left of the abdomen is good. Try to avoid muscles – their movement and electrical activity could interfere with the signal.
Google for “ecg 3 lead electrode placement” for other diagrams.
Step 3: Fake Pulse
The ArdECG0.ino sketch can produce a fake “pulse”. It’s not a very realistic fake but it produces pulses of about the right size at about the right frequency. It’s convenient to use it when debugging your unit.
The 100k resistors persuade the AD8232 that there are electrode attached. There are some pads on the AD8232 module PCB labelled RA, LA, RL. I just poked some wires into them.
Step 4: The Heart
Doctors think of the heart as a complex organ but to an electronics designer, it is simply a generator of electrical potentials – several tens of millivolts.
The pulse travels slowly to the muscles of the atria and to the atrioventricular node (AV node). The muscles of the atria contract and then relax. As they contract, they pump blood into the ventricles. As they relax, the atria take in blood through the veins from the body or the lungs.
The AV node delays the pulse (by 120-200mS) then sends it to the muscles of the ventricles. Electronically, it too is a relaxation oscillator but its period is much longer than the SA oscillator. It is “prematurely” triggered by the SA oscillator so they become entrained. If the SA oscillator fails, the AV oscillator can oscillate on its own as a backup system.
The muscles of the ventricles contract and then relax. As they contract, they pump blood to the body or the lungs.
The whole process takes around 500mS.
It takes more power to pump blood round the body so the biggest signal we see is from the muscles of the left ventricle.
Sodium, potassium and calcium ions are pumped across the membranes of the cells of the heart muscles. When a heart muscle is relaxed, the difference in ion concentrations causes a 90mV potential difference across the cell membrane. Inside the cell is more negative.
When an action potential occurs a muscle contraction is triggered, Sodium channels open, Na+ ions rush into the cell by diffusion and the voltage goes to zero. That’s called “depolarisation”. After a 100mS delay, potassium channels open, K+ ions rush out of the cell and re-establish the 90mV resting potential. That’s called “repolarisation”. Ion pumps then restore the ion concentrations. (Calcium ions are also involved but I’m ignoring them.)
When an action potential occurs in a cell, the cell next to it is triggered. So the action potential spreads through the muscle and also via the Purkinje fibers. It’s a slow process; no fast nerve conduction involved.
- Muscle cell conduction is 0.3–0.4 m/s.
- Purkinje fiber conduction is 2–3 m/s.
- Normal neuron conduction is 70-120 m/s.
Purkinje fibers can oscillate by themselves at 20-40 bpm and so act as a backup system if the SA and AV oscillators fail.
An ECG records the action potentials of the different muscles. The action potentials of the muscles are transmitted through the chest wall and skin by simple electrical conduction. So the conduction is fast. By the time it reaches the skin the signal is around 1mV.
Because different action potentials occur in different regions of the heart, by repositioning the ECG electrodes you can record activities in different muscles. With the electrodes at the left and right under the clavicles, you’ll get the classical PQRST shape you see in a textbook (called “Lead I”). If you position the electrodes elsewhere you can pick-up other details of heart activity; different positions for pairs of electrodes are called “axes”.
It’s confusing, when doctors talk about “leads” and “axes”. When they say “lead”, they don’t mean a lead – i.e. an electrode. Remember, what an ECG displays is the difference between two electrodes – it’s a differential amplifier. The LL or RL electrode acts as a ground to help with common-mode rejection. A “12 Lead” ECG has 6 electrodes called V1 to V6 which are in a line in front of and to the bottom-left of the heart. Then there are RA and LA near your armpits. There may be two reference electrodes: LL and RL; the extra one doesn’t seem to do much so there’s usually just one. Pairs of electrodes are also called “leads” – LA-RA is called “Lead I”, LL-RA is called “Lead II” and LL-LA is called “Lead III”. It’s a mess.
The correct placement is:
- V1 is placed on the 4th intercostal space on the Right side of the sternum
- V2 is placed on the 4th intercostal space on the Left side of the sternum
- V4 is placed in the 5th intercostal space in a perpendicular line from the left nipple
- V3 is placed between V2 and V4
- V6 is in the 4th intercostal space in the left mid-axillary line (from the armpit to the hip)
- V5 is placed between V4 and V6
(Right and Left are patient Right and Left. On most males, the 4th intercostal space is between the nipples and is the indentation or soft area between the ribs.)
The maths is:
- Lead I: LA – RA
- Lead II: LL – RA
- Lead III: LL – LA
- Lead aVR: RA – average of (LA,LL)
- Lead aVL: RL – average of (RA,LL)
- Lead aVF: LL – average of (RA,RL)
- Lead V1: V1 – average of (RA,RL,LL)
- Lead V2: V2 – average of (RA,RL,LL)
- Lead V3: V3 – average of (RA,RL,LL)
- Lead V4: V4 – average of (RA,RL,LL)
- Lead V5: V5 – average of (RA,RL,LL)
- Lead V6: V6 – average of (RA,RL,LL)
The different “leads” are like looking towards the centre of the heart from different directions in 3D (see diagram above). The directions are called “axes”. To add more confusion the heart also has an “axis” – the electrical activity is symmetrical about that axis. If part of the heart goes wrong, the heart’s axis might have “deviation”. If “leads” I, II and III look roughly the same, that’s normal; if they’re different, that’s “deviation”.
Broadly, what can go wrong with the whole system is that the nodes (oscillators) or the different muscles stop functioning properly. For instance, parts of the muscles might be starved of oxygen and they don’t produce an action potential. Or the SA node might run at the wrong rate or the SA and AV nodes might become disconnected and the oscillators run at different rates.
Step 5: Adding a Display
The display is a 2.8″ colour TFT LCD screen with a ILI9341 controller, 320×240 pixels. I chose a 320×240 SPI display because can be updated reasonably quickly and uses few Arduino pins.
Search eBay for “320 240 TFT SPI” and you’ll find a variety of displays. Get one that looks the same as the photo. A display without a touch screen is cheaper.
I don’t use the touch screen function in this project. I want to run the unit on 4 AA cells or a Li-ion cell. As the AA cells discharge their voltage falls. I’ve found that the Arduino, display and AD8232 work fine with a supply voltage as low as 3V but the touch-screen stops below 4.5V.
The LCD has the following pins:
- VCC 5V
- GND ground
- CS LCD chip select
- RESET reset
- DC data/command
- MOSI SPI bus MOSI of Arduino
- SCK SPI bus SCLK
- LED back light
- MISO SPI data out of LCD (ignored)
- T_CLK SPI bus SCLK (ignored)
- T_CS touch chip select (ignored)
- T_DIN MOSI of Arduino (ignored)
- T_DO SPI data out of touch (ignored)
- T_IRQ touch interrupt request (ignored)
The display I bought has a built-in 3V3 regulator. If you look on the back of the PCB, you’ll see it connected to the VCC pin. It’s a 662K chip. So the module can be powered by 5V and you can connect it directly to your 5V Arduino pin. The LED power pin can also be connected directly to the 5V pin.
(Check that your display has a 3V3 regulator. If it doesn’t and it requires 3.3V power then it takes around 50mA which is just at the limit of what the Arduino Nano’s 3.3V regulator can provide. So it may be a mistake to power the display from the Nano’s 3.3V pin. You’ll should supply your own regulator.)
The logic pins of the display require 3.3V signals. You can’t connect them directly to the 5V I/O pins of the Arduino. I’ve used resistors to drop the voltage.
Adafruit very kindly publish an ILI9341 library and several other libraries are available in Github and elsewhere. I tried a few and didn’t like any of them. Some simply didn’t work and all were huge. You write an Arduino sketch that draws a line and some text and you find your memory if 75% full. So I wrote my own drivers.
Wire up the display as shown and download the ArdECG1.ino sketch.
I’ve decided I don’t like the way the Arduino IDE uses “libraries”. It makes version control difficult. So I now keep the code needed to compile a sketch together. Put all these files in the same folder:
SimpleILI9341 has a standard set of drawing commands very similar to all such libraries.
Some of the “fast” libraries you can download use special timing loops and are upset when other, maybe slower, devices are used on the same bus. SimpleILI9341 is written in C rather than assembler so isn’t quite as fast as it could be but is much more portable and it shares the SPI bus politely with other devices. A Windows program can be downloaded which allows you to make your own fonts and icons.
You can download the ILI9341 data sheet from the web. You send it a command by
set DC low set CS low send a command byte set CS high
and send it data by
set DC high set CS low send zero or more data bytes set CS high
You can see how I do it in the tft_write functions. The data bytes might be a whole row of pixels or a setting for a control register.
The ILI9341Begin() function in the library shows you the initialisation command set I’ve chosen. You might want to change the commands if you choose a different ILI9341 display (e.g. with more pixels) or want a different orientation. I hope my code is easy for you to see how to change if you need to.
In the circuit diagram are components in a box labelled “Fake Pulse”. Do not include them in your final build. They are useful during development and debugging. In the ArdECG1.ino sketch there is a #define to enable/disable fake pulse generation. It’s somewhere near the top:
Comment out the line to remove the fake pulse.
Source: ECG Display With Arduino