Hi, I am wanting to collect multiple data points from the ear-clip heart rate sensor. I want to use two to get the heart rate of two people at the same time. I’m also wanting to using the GSR sensor (again two for two data inputs at the same time).
I’ve got the code from this site from both of these individually and I’ve got it to work for one person’s heart rate but I don’t know how to add all these sensors (and what the code would be) to the same base shield and arduino. Hopefully that makes sense.
This is the code for the heart rate clip which works fine.
// Function: This program can be used to measure heart rate, the lowest pulse in the program be set to 30.
// Use an external interrupt to measure it.
// Hardware: Grove - Ear-clip Heart Rate Sensor, Grove - Base Shield, Grove - LED
// Arduino IDE: Arduino-1.0
// Author: FrankieChu
// Date: Jan 22, 2013
// Version: v1.0
// by www.seeedstudio.com
#define LED 4//indicator, Grove - LED is connected with D4 of Arduino
boolean led_state = LOW;//state of LED, each time an external interrupt
//will change the state of LED
unsigned char counter;
unsigned long temp[21];
unsigned long sub;
bool data_effect=true;
unsigned int heart_rate;//the measurement result of heart rate
const int max_heartpluse_duty = 2000;//you can change it follow your system’s request.
//2000 meams 2 seconds. System return error
//if the duty overtrip 2 second.
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println(“Please ready your chest belt.”);
delay(5000);
arrayInit();
Serial.println(“Heart rate test begin.”);
attachInterrupt(0, interrupt, RISING);//set interrupt 0,digital port 2
}
void loop()
{
digitalWrite(LED, led_state);//Update the state of the indicator
}
/Function: calculate the heart rate/
void sum()
{
if(data_effect)
{
heart_rate=1200000/(temp[20]-temp[0]);//60201000/20_total_time
Serial.print(“Heart_rate_is:\t”);
Serial.println(heart_rate);
}
data_effect=1;//sign bit
}
/Function: Interrupt service routine.Get the sigal from the external interrupt/
void interrupt()
{
temp[counter]=millis();
Serial.println(counter,DEC);
Serial.println(temp[counter]);
switch(counter)
{
case 0:
sub=temp[counter]-temp[20];
Serial.println(sub);
break;
default:
sub=temp[counter]-temp[counter-1];
Serial.println(sub);
break;
}
if(sub>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
{
data_effect=0;//sign bit
counter=0;
Serial.println(“Heart rate measure error,test will restart!” );
arrayInit();
}
if (counter==20&&data_effect)
{
counter=0;
sum();
}
else if(counter!=20&&data_effect)
counter++;
else
{
counter=0;
data_effect=1;
}
}
/Function: Initialization for the array(temp)/
void arrayInit()
{
for(unsigned char i=0;i < 20;i ++)
{
temp[i]=0;
}
temp[20]=millis();
}
Hi there
please try below code. thanks.
[code]
const int Gsr0=A0,Gsr1=A1;
int Gsr_SensorValue0,Gsr_SensorValue1;
unsigned char counter1,counter0;
unsigned long temp1[21],temp0[21];
unsigned long sub1,sub0;
bool data_effect1 = true,data_effect0 = true;
unsigned int heart_rate1,heart_rate0;//the measurement result of heart rate
const int max_heartpluse_duty = 2000;//you can change it follow your system's request.
//2000 meams 2 seconds. System return error
//if the duty overtrip 2 second.
void setup()
{
Serial.begin(9600);
Serial.println("Please ready your chest belt.");
delay(5000);
arrayInit1();
Serial.println("Heart rate test begin.");
attachInterrupt(0, interrupt0, RISING);//set interrupt 0,digital port 2
attachInterrupt(1, interrupt1, RISING);//set interrupt 1,digital port 3
}
void loop()
{
Gsr_SensorValue0=analogRead(Gsr0);
Gsr_SensorValue1=analogRead(Gsr1);
Serial.print("Gsr_SensorValue0_Is:\t");
Serial.println(Gsr_SensorValue0);
Serial.print("Gsr_SensorValue1_Is:\t");
Serial.println(Gsr_SensorValue1);
delay(1000);
}
/*Function: calculate the heart rate*/
void sum1()
{
if(data_effect1)
{
heart_rate1=1200000/(temp1[20]-temp1[0]);//60*20*1000/20_total_time
Serial.print("heart_rate1_is:\t");
Serial.println(heart_rate1);
}
data_effect1=1;//sign bit
}
/*Function: Interrupt service routine.Get the sigal from the external interrupt*/
void interrupt1()
{
temp1[counter1]=millis();
Serial.println(counter1,DEC);
Serial.println(temp1[counter1]);
switch(counter1)
{
case 0:
sub1=temp1[counter1]-temp1[20];
Serial.println(sub1);
break;
default:
sub1=temp1[counter1]-temp1[counter1-1];
Serial.println(sub1);
break;
}
if(sub1>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
{
data_effect1=0;//sign bit
counter1=0;
Serial.println("Heart rate1 measure error,test will restart!" );
arrayInit1();
}
if (counter1==20&&data_effect1)
{
counter1=0;
sum1();
}
else if(counter1!=20&&data_effect1)
counter1++;
else
{
counter1=0;
data_effect1=1;
}
}
/*Function: Initialization for the array(temp1)*/
void arrayInit1()
{
for(unsigned char i=0;i < 20;i ++)
{
temp1[i]=0;
}
temp1[20]=millis();
}
void sum0()
{
if(data_effect0)
{
heart_rate0=1200000/(temp0[20]-temp0[0]);//60*20*1000/20_total_time
Serial.print("heart_rate0_is:\t");
Serial.println(heart_rate0);
}
data_effect0=1;//sign bit
}
void interrupt0()
{
temp0[counter0]=millis();
Serial.println(counter0,DEC);
Serial.println(temp0[counter0]);
switch(counter0)
{
case 0:
sub0=temp0[counter0]-temp0[20];
Serial.println(sub0);
break;
default:
sub0=temp0[counter0]-temp0[counter0-1];
Serial.println(sub0);
break;
}
if(sub0>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
{
data_effect0=0;//sign bit
counter0=0;
Serial.println("Heart rate0 measure error,test will restart!" );
arrayInit0();
}
if (counter0==20&&data_effect0)
{
counter0=0;
sum0();
}
else if(counter0!=20&&data_effect0)
counter0++;
else
{
counter0=0;
data_effect0=1;
}
}
/*Function: Initialization for the array(temp1)*/
void arrayInit0()
{
for(unsigned char i=0;i < 20;i ++)
{
temp0[i]=0;
}
temp0[20]=millis();
}<e>[/code]</e></CODE></r>
Hello, is there anybody active on this page anymore that can answer this question?
In the setup function of the code for two heartbeat sensors only temp1 is initialized. Is there a reason for that or was it a mistake ?