Basic ECG Circuit
The observation of the electrical activity of the heart is an area of interest from clinicians that diagnose and treat cardiac conditions. A diagnostic tool to observe these readings is an electrocardiogram (ECG). This instructable seeks to replicate existing ECGs using fundamental circuitry techniques learned from this course. A circuit that filtered out high frequencies and 60 Hz while amplifying the signal to levels that are able to be analyzed was built utilizing a low pass filter, band-reject filter, and instrumental amplifier respectively.
Create the Instrumental Amplifier
Create the instrumental amplifier in LTspice according to the schematic that is shown. This will be able to be verified if the output of the instrumental amplifier has a gain of 100 with a 20mV input simulation in the voltage source. Once this is complete, obtain a breadboard, 7 18kꭥ resistors, a 330ꭥ resistor, and 3 LM741/NS op-amps, and various jumper wires. Refer to the pin diagram and the schematic to build the circuit.
This can be verified using a function generator outputting a 20mV peak to peak sin wave hooked up to an oscilloscope. The oscilloscope peak to peak amplitude should be 2V. As shown.
Create the Low Pass Filter
Create a low pass filter in LTspice according to the schematic that is shown. This will be able to be verified if a 1V AC sweep from 1Hz to 200Hz of the low pass filter has a cutoff frequency of 150Hz in the LTspice simulation. Once this is complete, obtain a breadboard, a 15kꭥ resistor, a 47kꭥ resistor, a 0.035uF capacitor, a 0.068uF capacitor, an LM741/NS op-amp, and various jumper wires. Refer to the pin diagram and the schematic to build the circuit.
This can be verified using a function generator to various frequencies at a constant amplitude hooked up to an oscilloscope. The oscilloscope should show a drop in amplitude after 150 Hz.
Create the Band Reject Filter
Create a band-reject filter in LTspice according to the schematic that is shown. This will be able to be verified if a 1V AC sweep from 50Hz to 70Hz of the band-reject filter has a cutoff frequency of ~60Hz in the LTspice simulation. Once this is complete, obtain a breadboard, 2 1.5kꭥ resistors, a 490kꭥ resistor, 2 0.1uF capacitors, a 0.2uF capacitor, an LM741/NS op-amp, and various jumper wires. Refer to the pin diagram and the schematic to build the circuit.
This can be verified using a function generator to various frequencies at a constant amplitude hooked up to an oscilloscope. The oscilloscope should show a sharp drop in amplitude around 60 Hz.
Create the Complete Circuit
Wire the complete circuit by combining the various components. This should result in an output that has a gain of 100, a low pass cut-off frequency of 150Hz, and a band-reject cut-off of ~60 Hz. This is now ready for electrodes to be placed.
Obtain 3 ECG electrodes. Place one on the right wrist, one on the left wrist, and one on the ankle. Secure the right wrist electrode to one of the inputs on the instrumental op-amp, the left wrist electrode to the other input on the instrumental op-amp, and the ankle electrode to ground. Still connected to the oscilloscope, one should be able to see an ECG signal. An example is shown above. Congratulations!
Arduino Implementation
Obtain your arduino uno R3 and hook up the desired connections with the following code implemented. This code allows for a plotted ECG signal and BPM readings.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //starting serial communication
pinMode(A0, INPUT); //declaring A0 as the input pin that is connected to the output of the breadboard
}
//initializing variables for bpm calc
int thresh2 = 50; //upper threshold for range of detectable signal for bpm difference
int thresh1 = 30; //lower threshold for range of detectable signal for bpm difference
int initRead = 0; //first reading for bpm set to 0
float bpm = 0.0; //variable for bpm
int ignoreRead = 0; //checking variable for bpm loop
int pulse = 0; //second checking variable for bpm loop
unsigned long pulseTime1 = 0; //time of first signal in threshold
unsigned long pulseTime2 = 0; //time of second signal in threshold
unsigned long interval = 0; //interval between detectable signals for bpm calc
int state; //for extra credit, determiens
void loop(){
// put your main code here, to run repeatedly:
char val = Serial.read(); //for extra credit, reading signal from serial monitor in PDE
int x = analogRead(A0); //reading signal from breadboard output in A0
Serial.println(x); //printing signal and displaying on serial plotter
delay(10); //time delay for plotting
}
//bpm
if(x > thresh2 && ignoreRead == 0){ //if the signal is above upper threshold and dont ignore read
if(pulse == 0){ //if no first pulse
pulseTime1 = millis(); //returning ms
pulse = 1; // pulse to true
}
else{
pulseTime2 = millis(); //returning ms
interval = pulseTime2 - pulseTime1; //calculating pulse interval
pulseTime1 = pulseTime2; //shifting first pulse to be the second pulse for next calculation
}
ignoreRead = 1; //setting ignore read to true
}
//restarting loop
if(initRead < thresh1){
ignoreRead = 0;
}
bpm = (1.0/interval) * 60.0 * 1000; //bpm calculation converting to beats per minute
//printing to serial monitor
Serial.print(initRead);
Serial.print("\t");
Serial.print(PulseInterval);
Serial.print("\t");
Serial.print(bpm);
Serial.print((String)" BPM = "+ bpm);
Serial.flush();
}
}