Example Code for Arduino-Draw ECG (Digital Mode)
This example shows how to generate an ECG waveform in the Arduino Serial Plotter using the Heart Rate Sensor in digital mode.
Hardware Preparation
- DFRduino UNO (or similar)
- SEN0203 Heart Rate Monitor Sensor for Arduino
- IO Expansion Shield for Arduino (suggested)
- Some wires
Software Preparation
- Arduino IDE 1.6.6+ - Click to Download Arduino IDE from Arduino®
Wiring Diagram
- Attach this sensor to Arduino D2
- Set the sensor mode switch as D (digital)
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
2.Wrap on finger
3.Wrap on wrist
4.Wrap on the back of wrist
Sample Code
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
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.
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?
