ANALÓGICO: RITMO CARDICO

RITMO CARDIÁCO

KY-039 Finger Detector Módulo Sensor de Detección de latido para Arduino
Voltaje de funcionamiento: 5V
Uso IR LED y transistor óptico para detectar la pulsación en los dedos

CONEXIONADO:
  • Sensor pin S connect to Arduino pin Analoog 0 / A0
  • Sensor pin + (middle pin) connect to Arduino pin 5+
  • Sensor pin - connect to Arduino pin GND

CÓDIGO
 
// Pulse Monitor Test Script
int sensorPin = 0;
 double alpha = 0.75;
 int period = 100; 
double change = 0.0; 
double minval = 0.0; 
void setup () { 
 Serial.begin (9600);
 } 
void loop () { 
 static double oldValue = 0; 
static double oldChange = 0; 
int rawValue = analogRead (sensorPin);
 double value = alpha * oldValue + (1 - alpha) * rawValue;
 Serial.print (rawValue); 
 Serial.print (","); 
 Serial.println (value);
 oldValue = value;
 delay (period); 
}




CÓDIGO:

int ledPin = 13;
int sensorPin = 0;
double alpha = 0.75; //using 75% of the average of the previous values and 25% of the current value
int period = 100; // This is how long the code delays in milliseconds between readings (10 mSec)
double change = 0.0; //to be used to detect the peaks


void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
static double oldValue = 0; // used for averaging.
static double oldChange = 0;
int rawValue = analogRead(sensorPin); // This reads in the value from the analog pin
double value = alpha * oldValue + (1 - alpha) * rawValue; // Calculate an average using 75% of the previous value and 25% of the new
change = value - oldValue;
digitalWrite(ledPin, (change < 0.00 && oldChange > 0.00));

delay(period);
Serial.println("Red IR");
Serial.print(rawValue);
Serial.print(" ");
Serial.print(value);
Serial.println(" ");
oldValue = value;
oldChange = change;
}