Learn to make a remote heart rate monitor using a Pulse Sensor and ThingSpeak. 

Remote health monitoring is rapidly growing in the healthcare field. With tools like the Fitbit and Apple watch, people are able to monitor vital health data from anywhere in the world. Researchers, engineers, and health care professionals are continuously involved in research in this field with the aim of improving the quality of healthcare services. It is essential to monitor the proper functioning of the human body considering various parameters such as heart rate, body temperature, and pressure. Nowadays most of the wearables have these health monitoring features built-in.

If you are a person with an inclination towards biomedical technology, this is an exciting project you’ll want to try. This project will teach you how to build an IoT-based remote heart rate monitoring system with the ESP32. Once you set up this project, you can monitor your heart rate from anywhere in the world using a laptop or a mobile phone.

Let’s get started.

Required Hardware

  • ESP32
  • Pulse Sensor
  • Red LED
  • Breadboard and Jumper Wires
IOT_Heart_Rate_Monitor_JW_MP_image7.jpg

Required Libraries

Connecting the Pulse Sensor to the ESP32

The Fritzing diagram below shows the connections between the Pulse Sensor, the ESP32, and the LED.

IOT_Heart_Rate_Monitor_JW_MP_image4.png

Once your hardware is connected, it should look something like this:

IOT_Heart_Rate_Monitor_JW_MP_image16.jpg

The signal pin of the pulse sensor must be connected to an analog pin of ESP32. There is also an LED connected to the digital pin of the ESP32 that blinks according to the sensor pulses. 

IOT_Heart_Rate_Monitor_JW_MP_image14.jpg

Some analog pins read faulty values when reading the sensor data while the board is connected to a Wi-Fi network because there can be conflicts between the ADC and the Wi-Fi on the ESP32. So it is recommended to follow the exact pin arrangement I listed in the image above. Most of the time, GPIO pin 32 and 36 work fine with the Wi-Fi.

Heart Rate Monitoring System Overview

The following block diagram shows the entire setup for the system.

IOT_Heart_Rate_Monitor_JW_MP_image14.jpg

Some analog pins read faulty values when reading the sensor data while the board is connected to a Wi-Fi network because there can be conflicts between the ADC and the Wi-Fi on the ESP32. So it is recommended to follow the exact pin arrangement I listed in the image above. Most of the time, GPIO pin 32 and 36 work fine with the Wi-Fi.

Heart Rate Monitoring System Overview

The following block diagram shows the entire setup for the system.

IOT_Heart_Rate_Monitor_JW_MP_image5.png

The sensor collects heart rate data and pulses from the human body, the LED blinks according to the pulses. Then the ESP32 sends the data to the ThingSpeak cloud. In order to do that, the board must be connected to a Wi-Fi network.

The ThingSpeak platform gives us the flexibility to manage and store data. It also has smart tools and widgets to visualize and analyze data using graphs. It can be used to monitor real-time data and the result can be viewed remotely via a monitor, mobile phone, or laptop.

How to Set Up ThingSpeak for Remote Monitoring

Setting up the ThingSpeak IoT platform is very easy. First, you have to create a free account on ThingSpeak’s website.

IOT_Heart_Rate_Monitor_JW_MP_image3.png

Once you’ve signed up, create a new channel.

IOT_Heart_Rate_Monitor_JW_MP_image2.png

Then, create a field to save the beats per minute (BPM) value of the heart rate.

IOT_Heart_Rate_Monitor_JW_MP_image10.png

Once you create your channel, ThingSpeak directs you to a webpage with a customizable graph, like the one shown below.

IOT_Heart_Rate_Monitor_JW_MP_image1.png

Finally, click on the “API Keys” tab.

IOT_Heart_Rate_Monitor_JW_MP_image12.png
  • The “Write API Key” is useful when we attempt to write data or send data from the ESP32.
  • The “Read API Keys” can be used to monitor data from a remote device.

Full Project Code

The full project code can be found at the link below:

IoT Heartrate Monitor Code

Make sure to disable Arduino interrupts at the top of the code since the ESP32 doesn’t support hardware interrupts with the sensor and Arduino library.

IOT_Heart_Rate_Monitor_JW_MP_image15.png

Before uploading the code into the ESP32, add your Wi-Fi ID, password, ThingSpeak channel ID, and write API key.

IOT_Heart_Rate_Monitor_JW_MP_image9.png

We can get the BPM value of the heartbeat using the getBeatsPerMinute() function. The code uses an “if statement” to filter the values between 50 BPM to 100 BPM. Adding this in avoids uploading inaccurate sensor values to the ThingSpeak cloud.

The Arduino program reads sensor data and sends it to ThingSpeak every 20 seconds. You can adjust the upload speed by changing the intervalThingSpeak variable.

Finished Heart Rate Monitor Demo

Once you successfully set up the project, you can observe the heart rate pulses from the serial plotter. The ThingSpeak graph updates the BPM value every 20 seconds.

IOT_Heart_Rate_Monitor_JW_MP_image17.png

Download and install the ThingSpeak Viewer app to monitor the graph from your mobile device. For successful installation, make sure to have your channel ID and read API handy.

IOT_Heart_Rate_Monitor_JW_MP_image13.png

When you hold the sensor between your fingertips, the serial plotter shows your heart rate pulses in green. Once you take off your fingers from the sensor, a straight line displays on the graph.

IOT_Heart_Rate_Monitor_JW_MP_image6.png

ThingSpeak updates the BPM value with the date and the time.

IOT_Heart_Rate_Monitor_JW_MP_image8.png
IOT_Heart_Rate_Monitor_JW_MP_image11.png

Further Readings

The more you learn the more you grow, so don’t stop here. There is a lot of research available on this topic. As the next step, you can build a wearable health monitor. I encourage you to read more on this topic.

Jinani Wijesinghe
I am a mechatronics engineer and an electronics hobbyist. I love to share innovative projects with DIY enthusiasts across the globe.