Heart Beat Sensor
#include <MsTimer2.h>
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
unsigned int flag=0,count=0,sec=0;
int sensorValue = 0; // value read from the pot
int outputValue = 0;
void flash() {
static boolean output = HIGH;
sec++;
if(sec==30)
{
count=count*4;
Serial.println(count);
sec=0;
count=0;
}
}
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
if((sensorValue>800)&&(flag==0))
{
count++;
flag=1;
delay(100);
}
else if((sensorValue<100)&&(flag==1))
{
flag=0;
}
}