Example Code for Arduino-Draw ECG (Analog Mode)

This example demonstrates how to visualize an analog ECG waveform using the Heart Rate Sensor in Analog (A) mode with the Arduino Serial Plotter.

Hardware Preparation

Software Preparation

Wiring Diagram

SEN0203 Heart Rate Monitor Sensor for Arduino Connection Diagram
  • Attach this sensor to Arduino A1
  • Set the sensor mode switch as A (analog)

Other Preparation Work

Once you opened the box, you can find a black belt inside of the package. Thread it through the holes of the sensor as indicted in the photo. And then you could attach it on your finger (suggested), wrist or any other places where exposes blood vessels. Do not attach the belt too tight or too loose to your finger or the reading might be not stable. During the test, you should steady your finger and do not move too much, or the readings might be unstable.

1.Thread the belt through the holes

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

2.Wrap on finger

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

3.Wrap on wrist

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

4.Wrap on the back of wrist

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

Sample Code


/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A1);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(10);        // delay in between reads for stability
}

Result

After uploading the code, open the Arduino Serial Plotter and set the baud rate to 9600 to view the ECG waveform.

SEN0203 Heart Rate Monitor Sensor for Arduino

The switch is used to select the working mode of the module, setting the output signal to either Digital or Analog.
The switch setting must match both the code and the wiring. For example, if the switch is set to Analog (A) but the code uses digitalRead() or the module is connected to a digital pin on the Arduino, no valid readings will be obtained. The same issue applies in the opposite configuration.

Was this article helpful?

TOP