Boris LeonovSam KristoffArthur Brown
Published © MIT

Detecting Heart Rate with a Photoresistor

A photoresistor can sense the subtle changes in light intensity caused by your blood to detect your heartbeat!

IntermediateFull instructions provided2.5 hours29,309
Detecting Heart Rate with a Photoresistor

Things used in this project

Hardware components

OpenScope MZ
Digilent OpenScope MZ
×1
Arduino UNO
Arduino UNO
×1
General Purpose Quad Op-Amp
Texas Instruments General Purpose Quad Op-Amp
×1
High Speed Single Comparator
Texas Instruments High Speed Single Comparator
×1
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
×2
Single Turn Potentiometer- 100k ohms
Single Turn Potentiometer- 100k ohms
If you can get a multi-turn potentiometer it will be easier to adjust.
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Capacitor 100 µF
Capacitor 100 µF
×1
Capacitor 100 nF
Capacitor 100 nF
×1
Resistor 10k ohm
Resistor 10k ohm
Or a single 20k
×2
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
Resistor 82k ohm
You could also get two of the 100k potentiometers and set one to 82k.
×1

Software apps and online services

Arduino IDE
Arduino IDE
Digilent WaveForms Live

Story

Read more

Schematics

Pulse Detector Fritzing Schematics/Breadboard

Code

comparator calcs.xlsx

Arduino
This Excel spreadsheet will calculate the R3 and R4 values to set asymmetrical thresholds for the comparator. You can change the R5 column to a measured resistor value. Vl and Vh need to be changed to whatever thresholds are necessary to get a clean pulse from the heart rate.
No preview (download only).

Arduino Heart Rate Counter

Arduino
This code will calculate your heart rate based on pulses sent to it by the comparator.
#define INT0 3
float frequency;
long timeCount;
int counter;
long pulseStart;
int inputPin = 3;
boolean low;
float freqAvg;
float total;

void setup() {
  attachInterrupt(digitalPinToInterrupt(INT0), intrruption, CHANGE);
  counter = 0;
  timeCount = 0;
  frequency = 0;
  low = false;
  Serial.begin(9600);
  total = 15;
}

void loop() {
  timeCount = millis();
  while(millis() - timeCount < 5000){
    frequency = counter;
  }
  if(frequency > 3){
    total += frequency;
    total -= freqAvg;
    freqAvg = total/3;
  }
  showHR();
  counter = 0;

}

void intrruption(){
  if(digitalRead(3) == 0){
    fallDetect();
    low = true;
  }
  else if(digitalRead(3) == 1){
    widthCheck();
  }
}

void fallDetect(){
  pulseStart = millis();
}

void widthCheck(){
  long pulseEnd = millis();
  if((pulseEnd - pulseStart > 200) && (pulseEnd - pulseStart < 800) && low){
    counter++;
    low = false;
  }
}

void showHR(){
  Serial.print("Heart rate = ");
  Serial.println(freqAvg * 12);
  
}

Credits

Boris Leonov

Boris Leonov

10 projects • 24 followers
Electrical engineering student in the Seattle area. Electrical and mechanical DIY enthusiast. Fixer of things, large and small.
Sam Kristoff

Sam Kristoff

35 projects • 53 followers
R&D Director at NI
Arthur Brown

Arthur Brown

14 projects • 30 followers
Applications engineer and digital logic geek

Comments