heart beat sensor with Arduino|heart pulse measurement

Heart Beat Sensor is used blood pressure and body temperature are very important parameters to known for human body. We go to doctors that use different kinds of apparatuses to know the heart beat of a human. In this tutorial, we are going to make our own heart beat sensor that will tell us the heart rate. We will make an Arduino based heart beat sensor that will tell us the number of pulses in a minute when we will place a finger on it.

Working of Heart beat sensor

The module uses an infrared led (IR) and a photo transistor to detect the pulse of the finger and whenever a pulse is detected, red led flashes. There will be led on the light side of the finger and a photo transistor on the other side of the finger. Photo transistor is used to obtain the flux emitted. The resistance of the photo resistor will change when the pulses will change.

Heat pulse sensor Pin Out

The heart beat sensor module has three pinsheartbeat-sensor-pin-out

Signal: This will be connected to the analog pin of the Arduino

5V: This will be connected to the 5V pin of the Arduino

GND: This will be connected to the ground of the Arduino

Heat beat sensor interfacing with arduino

heartbeat sensor interfacing with arduino

The connections are very easier. First connect the 5v and gnd pin of the module with the 5v and the gnd of the Arduino and then connect the sensor pin to the A0 of the Arduino.

heart beat sensor with arduino code

This code is for the testing of heart pulse measurement.

int led_Pin = 13;                                      // initializing the led pin

int output_Pin = A0;                                // initializing the sensor output pin

//initializng other variables

double alpha = 0.75;

int period = 200;

double change = 0.0;

void setup ( )                           // Code written in it will only run once.


  pinMode (led_Pin, OUTPUT);                   // declaring led pin as output

  Serial.begin (115200);                                   // setting baud rate at 115200


void loop ()


    // initializing other variables

    static double oldValue = 0;

    static double oldChange = 0;

    int rawValue = analogRead (output_Pin);                                         // Reading the sensors values

    double value = alpha * oldValue + (1 - alpha) * rawValue;         // calculating values using the formula

    Serial.print (rawValue);              // printing the sensor output value on the screen

    Serial.print (",");                                                                                          

    Serial.println (value);             // printing the heart beat value on the screen

    oldValue = value;

    delay (period);


Heart Beat sensor with LCD attached

In this example we will attached the heart pulse sensor with Arduino and a lcd. Arduino will control the whole system. Arduino will read the pulses from the heart beat sensor module and will calculate the heart rate and will show it to the LCD.The output pin of the heart beat sensor is connected to the pin 8 of Arduino. LCD is connected to Arduino in the 4-bit mode. VCC and gnd of sensor are connected to the vcc and gnd of the Arduino. When we will press the push button the system will start to count the pulses.

heartbeat sensor with lcd display

There are many methods for calculating the heart beat but here we will take only five pulses and will calculate the total heart rate in minute by using this formula.

 Five pulse time = time2 – time1

 Single pulse time = Five pulse time /5

 Rate = 60000/ Single pulse time;

where time1 is first pulse counter value

time2 is list pulse counter value

rate is final heart rate


The components used for making this project are as follows.

  • Arduino (we have used Arduino uno)
  • 16 X 2 LCD
  • Heart beat sensor
  • Push button

Code of heart beat measurement 

This code is for displaying the output of heart pulse sensor on the lcd. install the library of the lcd before uploading the code.

#include<LiquidCrystal.h>                                            // including the lcd library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);                             // declaring pins for lcd

int in = 8;                                                      // declaring pin 8 for sensor output
 int Reset=6;                                                   // declaring pin 6 for push button
 int start=7;                                                    // declaring pin 7 for other push button
 int count=0,i=0,k=0,rate=0;                                         // initializing other variables

unsigned long time2,time1;
 unsigned long time;

byte heart[8] = 

void setup ( )
   lcd.createChar(1, heart);                            
   lcd.begin(16,2);                                               // starting the lcd
   lcd.print("Heart Beat ");                              // printing heart beat on the display
   lcd.setCursor(0,1);                                         // setting the cursor from start
   lcd.print("Monitering");                              // printing monitoring on the display
 // initializing the pins as input pins 

pinMode(in, INPUT);
   pinMode(Reset, INPUT);
   pinMode(start, INPUT);

// setting the push buttons state as high
   digitalWrite(Reset, HIGH);
   digitalWrite(start, HIGH);
   delay(1000);                                     // giving a delay

void loop()
   if(!(digitalRead(start)))                       // checking if the start button is pressed or not
     lcd.print("Please wait.......");              // displaying the please wait on the lcd
     while(k<5)                                     // applying another condition
      if(digitalRead(in))                         // reading from the sensor
       // applying the formula for calculating the heart beat

       lcd.clear();                                       // clearing the lcd
       lcd.print("Heart Beat Rate:");                    // printing heart beat rate on display
       lcd.setCursor(0,1);                            // setting the cursor at start
       lcd.print(rate);                            // printing the heart beat on the display
       lcd.print(" ");
   if(!digitalRead(Reset))                         // checking if reset button is pressed or not
      lcd.clear();                              // clearing the lcd
       lcd.print("Heart Beat Rate:");          // printing heart beat rate on display
       lcd.setCursor(0,1);                    // setting the cursor at start
       lcd.print(rate);                       // printing the heart beat on the display



  1. berihu mebrahtom November 19, 2016
  2. Muhammad Furqan January 17, 2017
    • nitesh April 8, 2017
  3. sagar March 29, 2017
    • ABDUL AWAL October 11, 2017
  4. Luis Jerry Bailon Ortiz July 2, 2017
  5. Akshay ac December 14, 2017
  6. Heena shaik January 23, 2018
  7. T.Krishnamoorthy February 20, 2018
  8. Dengale Bhagyashri B March 22, 2018

Add Comment

Learn ESP32 programming with Arduino IDE with 73% DISCOUNT