The optical heart rate sensor supports straight 
analog or digital signal output
which allows us to either read the
pattern of the heartbeat
or count  real-time heart rate
Using the most basic
Arduino IDE building examples
It comes with a wrist band 
and a 3 pin jumper cable
To start, just attach the sensor to our body
and hook up with an Arduino board
Before moving into setup,
let's first take a look at the optical heart rate sensor
and how it works
The optical heart rate sensor is based on
PPG —— Photoplethysmography Technology
which may sound horrible to most of us
However, it is based on a very simple fact 
—— blood absorbs green light
Each time our heart beats, 
it pumps a blood pulse into vessel
As a result, 
more green light is absorbed
Therefore, the intensity of reflected lights 
captured by the optical sensor
gives us the density of the blood pulse
PPG technology is widely used in
consumer wearable devices
such as fitness watches or smart wristbands
It is also used in professional medical devices 
for fast diagnosis
However, we would not recommend use these 
for diagnosis or medical treatment
But we can still get quite accurate reading
with the optical heart rate sensor
Here are a few tips
Tip number one
Stick the sensor on to area with higher transparency
so the sensor will be 
more sensitive to the pulse change
Tip number two
Stick the probe on the skin 
with a stable pleasure
Any change of their relative position 
may affect the intensity of the reflect light
Remember, a blood pulse can be generated by other factors 
such as instant body movements
or simply a press on the surrounding skin
Tip number three
Make sure the body be still 
during the measurement
or put the sensor in a place that is
less likely to be affected by limb movements
such as chest, forehead
Apart from PPG, there is another measuring technology 
that is more trusted and accurate
It is called ECG —— electrocardiography
which namely measures the electric pulse 
generated by cardiac movement
Here is another video explaining ECG heart sensor
and the sensor is available here
The following comparison gives us 
an idea of pros and cons
In general, PPG is good 
in terms of lightness and simplicity
while ECG is more accurate
Now it's time to get our heart rate monitor 
up and running
Connect to an Arduino board 
with an expansion shield or jumper wires
the optical heartrate sensor supports 
both analog and digital output
The analog output gives a pattern of heartbeat
while the digital mode only gives pulse count
Switching between two modes is extremely simple
To start with analog mode,
turn the switch on the sensor to A side, 
which stands for analog
Connect the Arduino board to computer
Connect the signal pin to analog 0 
and power up the sensor by 5 volt pin and GND pin
Open IDE, select the right board type and comport
Then go to example - analog, 
and open analog in/out signal
Upload the code to Arduino board
Once successfully uploaded, open the serial plotter
we will be able to see some random readings
Now put the sensor on to finger or attached to skin
Hold still and wait for a few second
heartbeat will be shown in the monitor
Meanwhile the onboard LED also blinks 
at the pace of the heartbeat
We can also read the value from devices 
such as an oscilloscope
but we have to make sure the power supply 
doesn't exceed its 3.3 to 6 volt related voltage
Sometimes we only need 
the pulse count
Put it in digital mode
To start digital mode, keep the circuit unchanged 
and turn the A/D switch to D
Of course we may use any digital input pin 
to read the pulse
Heartbeats are now transformed into square waves
so every switch between high to low 
stands for a pulse change
To achieve this, a standard A to D converter 
is not enough
since the average voltage shifts throughout the time
therefore we need the A to D converter 
since the voltage change instead of the voltage itself
The following circuit is used to compare 
the voltage difference of the same analog signal
but between a short intervals which tells us 
whether the voltage is going high or low
If you are interested in going deeper，
the schematic diagrams and other specifications 
can be found here via wiki page
Anyways, based on the square wave we can calculate 
the heart rate by counting how many times
the voltage shifts from low to high or also
high to low in a certain time interval
To do this in Arduino， we have a library 
and sample code available from the wiki page
Imported into Arduino IDE
Heart pulse is calculated in every 10 seconds
Now the heart rate is being updated in real time 
upon a beat pulse is detected
and real-time heart rate will be displayed 
as a number in the serial monitor
Okay!
That's all about this optical heart rate sensor
Remember, the sensor should never be used 
for medical diagnosis or treatment
If you think this video is helpful 
please give us a THUMBS UP
Please also subscribe to our Channel
To know learn about 
the latest open-source hardware modules
If you have any thoughts or question 
please also leave a comment below
Thanks for watching!
