ECG click measures the electrical activity of a beating heart through electrodes taped to the skin. It requires little setup, and the final measurement results can be displayed as an Electrocardiogram using a free app.
Note: ECG click is a prototyping tool, not a medical-grade device. Do not use it to diagnose patients.
Necessary components
In order to record ECG, you will need the following:
- ECG click
- Cable
- Disposable electrodes
All of the above items are sold in our store. You can buy them separately, or as an ECG kit bundle. The disposable electrodes come in a pack of 30.
Circuit design and operating principles
There is onboard 3.5mm phone jack that is used to connect cables/electrodes to the click board. Electrode should collect voltage form the skin (few millivolts). Signal from the jack should be amplified and filtered. Therefore, ECG click can be divided into seven blocks.
- Protection - Provides ESD protection (protects click), Overvoltage and Overcurrent protection (protects the human). In addition to protection, the input block filters and prevents radio waves fro “enter” the preamplifier.
- Preamplifier – is implemented through three operational amplifiers configured as an instrumentation amplifier (IA – amplifies the voltage difference between “+” and “-“ electrode) which at its output provides a single-end signal.
- High-Pass filter – should eliminate the DC component of the signal (ƒc = 1.6Hz). It is a passive RC filter (first order).
- Amplifier – provides additional amplification that can be adjusted using the trimmer potentiometer VR1. This is to that the analog output could accommodate to the input voltage range of the ADC. The amplifier is implemented using an operational amplifier in a non-inverting configuration.
- High-Pass filter – Should eliminate the DC component of the signal (ƒc = 0.16 Hz) this time after the amplifier. It is also a passive RC filter (first order).
- Low-Pass filter – Should limit the frequency range to 60Hz. It is a third order active filter with a gain of 15 (second order Sallen-Key filter topology + passive RC filter first order = third order filter).
- DRL circuit (Driven Right Leg) – this type of circuit is often added to biological signal amplifiers to reduce Common-mode interference. Amplifiers for bio signals, such as ECG, measure very small electrical signals emitted by the body (measured in miliVolts or even microVolts). Unfortunately, the human body can also act as an antenna which picks up electromagnetic interference, (particularly 50/60 Hz noise from electrical power lines. This interference can obscure the biological signals, making them hard to measure. Right Leg Driver circuitry is used to eliminate interference noise by actively canceling it. It is a selective amplifier stage that shifts the phase of signal for 180° (inverting) and returns it to respondents in order to cancel.
Hardware configuration jumpers and settings
ECG click has one jumper and a trimmer potentiometer for setting the output voltage to match the input voltage level of the ADC which will be used.
The SMD (0805) jumper determines its output voltage range. When you connect all three electrodes to each other, the output should be a constant voltage (either 1.024V or 2.048V depending on the jumper position). This value is the zero-voltage line on the graph. The positive part of the ECG waveform will go above zero and the negative part will go below zero.
The trimmer potentiometer is for adjusting the gain. So if we set the jumper to 2.048 position (zero is now 1.024V) that means that the gain should be set so that the ECG waveform is in the range of 0-2.048V. If we set the jumper to the 4.096 position (zero is now 2.048V), the gain should be set so that the ECG waveform is in the range of 0-4.096V.
For optimal results, the target board MCU should have at least a 10-bit ADC (12-bit recommended). Sampling rate should be at least 256Hz.
We also recommended that the target development board is powered from the battery via a connector for external power supply.
Hooking up the electrodes
Electrocardiography is performed by measuring the heart's electrical activity through electrodes taped to the surface of the skin. The three electrodes are placed on the left arm, right arm and the left side of the abdomen (below the heart), on the left leg.
Here's how the electrodes are marked and color coded:
- Left leg (LL) – red
- Left arm (LA) – black
- Right arm (RA) – white
Tips for better results:
- Try not to move much while measuring, because the electrodes will pick up noise from muscle activation
- Experiment with the positioning of the disposable electrode pads
- Use new pads for each measurement
- Clean the skin area where you want to apply the pads
If you want visual instructions, see our ECG click setup guide
Programming
The code shown here initializes the ADC for measuring the ECG, and UART for talking to the PC. When the button is pressed, the timer interrupt will be initialized. An interrupt is generated every 3.9 ms, upon which the MCU gathers ADC and time data, and sends it to the PC over UART, until the timer reaches 15 seconds.
1 #include <stdint.h>
2 #include <stdbool.h>
3
4 void InitTimer1(){
5 T1CON = 0x8010;
6 T1IP0_bit = 1;
7 T1IP1_bit = 1;
8 T1IP2_bit = 1;
9 T1IF_bit = 0;
10 T1IE_bit = 1;
11 PR1 = 39000;
12 TMR1 = 0;
13 }
14
15 static bool read_flag = false;
16 static volatile uint32_t interrupt_ctr = 0;
17 uint32_t adc_reads_ctr = 0;
18 uint32_t timer_reads_ctr = 0;
19 static volatile uint32_t seconds_counter = 0;
20 double adc_reads;
21 double timer_reads;
22
23 void main()
24 {
25 uint32_t i = 0;
26 char timer_read_string[10];
27 char final_string [20];
28
29 TRISB8_bit = 1; // Set RA1 pin as input
30 TRISA15_bit = 1;
31 ad1pcfg = 0x0100;
32 ADC1_Init();
33
34 UART5_Init(57600);
35 delay_ms(500);
36
37 while(1)
38 {
39
40 if (Button(&PORTA, 15, 10, 1))
41 {
42 Uart5_Write_Text("STARTrn");
43 delay_ms(500);
44 InitTimer1();
45 EnableInterrupts();
46 }
47
48 if (read_flag == true)
49 {
50 T1IE_bit = 0;
51 adc_reads = ADC1_Get_Sample(8);
52 timer_reads = ((double)interrupt_ctr)*3.9;
53 inttostr(adc_reads, final_string);
54 floattostr(timer_reads, timer_read_string);
55 strcat(final_string, ",");
56 strcat(final_string, timer_read_string);
57 ltrim(final_string);
58 Uart_Write_Text(final_string);
59 Uart_Write_Text("rn");
60 read_flag = false;
61 T1IE_bit = 1;
62 }
63
64 if (seconds_counter == 15)
65 {
66 T1IE_bit = 0; // disable global interrupts
67 Uart_Write_Text("ENDrn");
68 while(1);
69 }
70
71 }
72
73 }
74
75
76 void Timer1Interrupt() iv IVT_TIMER_1 ilevel 7 ics ICS_SRS
77 {
78 read_flag = true;
79
80 interrupt_ctr++;
81 if (interrupt_ctr % 256 == 0)
82 seconds_counter++;
83
84 T1IF_bit = 0;
85 }
Code examples for ECG click, written for MikroElektronika hardware and compilers are available on Libstock
mikroPlot
MikroPlot is a graph generator. It’s a simple tool to help you visualize sensor data recorded over time. It’s suitable for bio signals (ECG, EEG, EMG) as well as environmental data logging (temperature, humidity etc). The app can receive data sets directly from a microcontroller through a USB UART connection.MikroPlot is a graph generator. It’s a simple tool to help you visualize sensor data recorded over time. It’s suitable for bio signals (ECG, EEG, EMG) as well as environmental data logging (temperature, humidity etc). The app can receive data sets directly from a microcontroller through a USB UART connection.
A tutorial for generating an EKG in mikroPlot is available on learn.mikroe.com