Experimental Objective
To record heart rate using a finger heartbeat monitoring module.
Equipment
Stduino UNO/Nano; DuPont cable; finger heartbeat monitoring module
Code demonstration.
Code: Select all
int ledPin = 13;
int sensorPin = A0;
double alpha = 0.75;
int period = 20;
double change = 0.0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT_ANALOG);
Serial.begin(115200);
}
void loop()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead(sensorPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;//This smoothing is the weighted average of the current and previous measurement data
Serial.println(value);
oldValue = value;
delay(period);
}
The values output from the serial port are copied to EXCEL, and the following line graph can be obtained (or an external LCD for real-time monitoring). It can be seen that in about 16 seconds there are 32 waves. This indicates on the one hand that the heartbeat is a bit fast, reaching 120 beats a minute. Also, this monitor is only suitable for learning and not for any medical use.

Caution
Block out the module as much as possible, or even put it in a small black box for experimentation.
Do not pinch the sensor directly with your hand to measure, then you will find that the graph lines drawn are messy, which does not mean that your heart rate is not aligned. The correct method is to measure the nail cap.