Example Code for Arduino-Sampling and ECG Output
Last revision 2026/01/07
This article offers a detailed tutorial on utilizing Arduino for ECG signal sampling and output, including hardware setup, software guidelines, and practical advice to optimize ECG signal quality, ensuring users can effectively measure and analyze heart rate signals.
Hardware Preparation
- DFRduino UNO (or similar) x 1
- Heart Rate Monitor Sensor x 1
- Sensor cable - Electrode Pads (3 connectors) x 1
- Biomedical Sensor Pad x 1
- Jumper wires
Software Preparation
- Arduino IDE V1.6.6 or above, Click to Download Arduino IDE from Arduino®
Wiring Diagram

Other Preparation Work
| NOTE: An ECG signal can be quite noisy due to surrounding muscle activity. The further the sensor pads are from the heart, the more muscle noise you will see. To improve the signal quality, follow these simple tips: Keep sensor pads as close to the heart as you can Make sure the RA and LA sensor pads are on correct sides of the heart Try not to move too much while taking a measurement Try to use fresh pads for each measurement. The pads loose the ability to pass signals with multiple applications Prepare and clean the area you plan to stick pads. This will help make a good connection (hair is not a good conductor) You may have to adjust sensor placement for different individuals |
|---|
Sample Code
/*!
* @file HeartRateMonitor.ino
* @brief HeartRateMonitor.ino Sampling and ECG output
*
* Real-time sampling and ECG output
*
* @author linfeng([email protected])
* @version V1.0
* @date 2016-4-5
*/
const int heartPin = A1;
void setup() {
Serial.begin(115200);
}
void loop() {
int heartValue = analogRead(heartPin);
Serial.println(heartValue);
delay(5);
}
Result
Step 1. Open the Arduino IDE 1.6.6 (or above) "Serial Plotter";

Step 2. Then you could see the output signal from the microcontroller - A1 port, the ECG.

| NOTE: If you found there was a lot of jamming waveforms, they may come from the body's static electricity. Touch something metal to discharge any static electricity. More read on WikiHow. |
|---|
Was this article helpful?
