Connecting 2 sensors (GSR and ear-clip heart monitor) on Arduino Uno


For my personal/school project, I wanted to take heart rate and GSR readings from two people having a hug and turn them into music, ie I wanted to hear how it sounds to hug my children :slight_smile:
How I turn into music or animation is second part, I’m still struggling with the first part!

I bought the sensors from here, and have used their code, which works fine individually. I have an Arduino Uno, Seeeduino, Base Shields and using their set up, I can make everything work.

I want to be able to combine the code and the hardware I’ve read a few tutorials to do this and come up with this (I’m not using the LED but I left in anyway in case I do)

// 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
#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.

const int GSR = A0;
int sensorValue = 0;
int gsr_average = 0;

void setup()
  pinMode(LED, OUTPUT);
  Serial.println("Please ready your chest belt.");
  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]); //60*20*1000/20_total_time
  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);
  switch (counter)
    case 0:
      sub = temp[counter] - temp[20];
      sub = temp[counter] - temp[counter - 1];
  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!" );
  if (counter == 20 && data_effect)
    counter = 0;
  else if (counter != 20 && data_effect)
    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();
  1. I am trying to record the outputs from both, and am using TeraTerm to capture and store the data. Currently, on TeraTerm I can log the heart rate, but not the GSR. I’m guessing my code is not good and is not able to record both inputs.

  2. I am recording the outputs into a excel file which is then going to be plugged into animation software.

If anyone has a better thought on how to do this, I’d love to hear it. I’d originally thought about using pluggin for Unreal Engine that my friend recommended but I’d be starting again trying to learn Unreal.

Thanks for you time and all y’all on the forums. Even if you can’t help on this project, I appreciate you helping us newbies!

You should not Serial print inside of an Interrupt Service Routine (ISR). Interrupts are disabled during an interrupt and Serial print depends on interrupts to work. Almost all of your code is in the ISR. ISRs should be as brief as possible. Just set a flag inside the interrupt, when an interrupt occurs, and then in loop() read the state of the flag. In loop(), if the flag is set, do the processing there and clear the flag.

Thank you! I will give that a try

Hi there,

Did you succeed in integrating your two sensors? I'm thinking about a project using these two sensors as well. I realize your post is a couple years old, but thought I'd try anyway!