MikroElektronika Learn

Click Boards

Microcontrollers have a Heart too

7 Sep , 2016  

Heart rate sensors are an interesting way to use IR LEDs (Infared Light-Emitting Diodes) and photo diodes to find a hearts’ pulse. Amazingly, the intensity of light received through the photo diode is actually different depending on how much blood is in your arteries. In this blog we will cover a photodiode’s basic operation, and how to use our Heart rate 3 click library to find beats per minute.


Photodiodes are used for detecting light. They use built-in lenses and optical filters to measure the light absorbed by the surface area. The photodiode then takes the amount of light absorbed and converts it to an electric current that can be used to measure the intensity of light being absorbed. When you shine an Infared LED through your finger the amount of light that is reflected back into the photo diode can be measured. The way that the Heart rate 3 senses pulses in your finger, is by measuring the difference in intensity over time. Every time your heart pulses, the arteries in your finger are filled with blood and therefore the intensity of the light decreases.


Heart rate 3

Heartrate 3 uses three LEDs and a photodiode to detect the intensity of light returned. It also includes the AFE4404 by TI that includes a 6-bit programmable LED current for all three LEDs, and individual DC offset subtraction DAC at TIA (Transimpedance Amplifier) input for each LED and ambient phase which allows us to increase the accuracy of the sensor and remove the noise from the signal. Along with hardware, there is also a way to average the 24-bit output from the photodiode before sending to the BPM algorithm for better noise cancellation. To use the Heart rate 3 it is very easy, here is a code example of calibrating the sampling frequency of the BPM function to ensure accuracy.

Every time that the all three LEDs have finished sampling and converting the ADC_RDY interupt is triggered, and using the ExtInt function we are incrementing a count variable and sending the LED1 ambient light data to the heart rate algorithm. Every 1 second a timer interrupt is triggered, capturing that count variable, displaying it on the terminal through serial port, and then resetting the counter to 0. If the timing is done correctly for the conditions of the heart rate 3, the counter should increment to 100 every 1 second. A way we can calibrate the frequency of samples we send to the algorithm, we can add a divider to the interrupt that sends the data to the algorithm like this…

If we are getting something like 120 samples a second, we will need to change the actual timing of the sampling and converting on the MCU. This can be done with functions in the hardware layer, and referencing the datasheet. By default, when you initialize the Heart rate 3, the PRF (Pulse Rate Frequency) divider is set to 1 and the timing values are set to a default value defined in the datasheet. If we want to divide the PRF by more than 1, we simply divide all of the timings by that same number, for example here is the init function while the divider is set to 1.

And here is an example of when the PRF divider is set to 5.

With this calibration technique, the great heart rate algorithm, and a steady finger on the click board it is easy to find your heart rate. In these examples I have sent the LED1 ambient values to the algorithm for higher accuracy. In some cases, it would be better to send LED1 values instead, but that will have to be determined by the user.

Source code can be found on either Libstock or Github.


Heart rate sensors are awesome, and with a good library they can be very accurate at finding pulses without much noise. Heart rate 3 is a great example of using one of the most accurate heart rate sensors out there, and a great library to produce a heart rate with ease.


Products mentioned

, , , , , , , ,

Firmware Engineer at MikroElektronika from Oregon with a passion for learning and programming.