# 10.3 Pulse Monitor

## Hardware Wiring

![Pulse Monitor](https://2341898987-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LCFDbcteyTR3tQSs-5x%2F-LCFE4dCRQBMq1ajywfh%2F-LCFEE6mO7K0CPlVb5FL%2F035_pulsemonitor.jpg?generation=1526059563366908\&alt=media)

## Sketch

The code can be found at [Examples\_Arduino - sensor-kit-for-arduino - \_035\_PulseMonitor - \_035\_PulseMonitor.ino](https://github.com/LongerVisionRobot/Examples_Arduino/blob/master/sensor-kit-for-arduino/_035_PulseMonitor/_035_PulseMonitor.ino).

```
int ledPin=13;
int sensorPin=0;

double alpha=0.75;
int period=20;
double change=0.0;

void setup()
{
  pinMode(ledPin,OUTPUT);
}

void loop()
{
  static double oldValue=0;
  static double oldChange=0;
  int rawValue=analogRead(sensorPin);
  double value=alpha*oldValue+(1-alpha)*rawValue;
  change=value-oldValue;

  digitalWrite(ledPin,(change<0.0&&oldChange>0.0));

  oldValue=value;
  oldChange=change;
  delay(period);
}
```
