Generating ECG Waveform

I am trying to generate ECG waveform with Arduino uno and AD8232 sensor, but not getting a an expected output

Since we have no idea about the wiring or the code there is not much that people can do to help you.

Please provide a wiring diagram or schematic, please indicate if you're using an AD8232 module (please provide link, preferably to the schematic of it) or a bare chip (schematic required).

Please provide your code; don't forget to use code tags as described in https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems.

I have no experience with the AD8232 so probably can't help further.

// Define the pin for the ECG output
const int ecgPin = A2;

void setup() {
  // Start the Serial communication
  Serial.begin(9600);
}

void loop() {
  // Read the ECG signal
  int ecgValue = analogRead(ecgPin);

  // Print the value to the Serial Monitor
  Serial.println(ecgValue);

  // Small delay to stabilize the readings
  delay(20);
}


I am getting this output from the code. But , i am not able to detect correct position of Q and S

link?

https://www.google.com/search?q=ARD8232+sensor+datashewtr+download&rlz=1C1CHBF_enIN1130IN1130&oq=ARD8232+sensor+datashewtr+download&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIJCAEQIRgKGKABMgkIAhAhGAoYoAHSAQkxOTU0M2owajeoAgiwAgE&sourceid=chrome&ie=UTF-8

Setting the baudrate to 115200 or 230400 will give more time for ADC readings.

The signal looks good enough to find Q in the ECG.

(source image unknown, sorry)

Please post your analysis code, how you search for Q and the other points?

This link give me crap, please provide requested information without typos

Is an amplifier, given you have a good signal it does its job.

I think that a lot of your problem is that your code keeps continuously reading the output of the ECG circuitry, and the waveform just keeps on scrolling past.

I would suggest doing something like the following:

// Define the pin for the ECG output
const int ecgPin = A2;

const int buttonPin = 12;
const int ledPin = 13;

unsigned int sample[500];
unsigned int output = 0;

void setup() {
  // Start the Serial communication
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Read the ECG signal
  // take 500 samples
  digitalWrite(ledPin, HIGH);
  for (int i = 0; i < 500; i++) {
    sample[i] = analogRead(ecgPin);
    delay(5);
  }
  digitalWrite(ledPin, LOW);

  // display the waveform at a leisurely pace.
  for (int i = 0; i < 500; i++) {
    output = (sample[i]);
    Serial.println(output);
  }

  while (digitalRead(buttonPin)) {
    // wait for button to be pressed before moving on to next sampling period.
  }
}
  • My code takes 500 readings (enough to fill the serial plotter screen), and stores them in an array.
  • It then prints the array on the serial plotter, to give a stationary trace.
  • The code then pauses so that you can view the waveform at your leisure.
  • You then press a button to take another set of readings.
  • The internal LED is used to indicate when the measurements are being taken.

As I don't have an AD8232 sensor, I used an arbitrary waveform generator to provide a simulated ECG signal to test the code:

Now that the waveform is stored in an array, it should be possible to analyse the data to detect 'Q' and 'S'.

It might be easier just to detect 'R' by setting a threshold, and noting the time using millis(), when the signal goes above the threshold.

1 Like

That is indeed easy to recognize.

The time between two R peaks determines the heartbeat rate.

That time gives an indication of

  • the interval to search for Q minimum
  • the interval to search for S minimum
  • the interval to search for P maximum
  • the interval to search for T maximum

Note that the S minimum is also the absolute minimum of the signal.
So it can be found with a threshold search as @JohnLincoln described too.

1 Like


Attached image i am getting as an output after applying high pass and low pass filter in the code. But not able to detect correct position of P,Q R and S. In this waveform ,sometimes Q is greater than S or sometimes it is equally positioned which is not correct.

That image is the same (only smaller) as the one that you said you got from the code in post #3.

The code in post #3 does not have high pass and low pass filtering.

I have already applied low pass and high passs filter as well then also I am getting same waveform.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.