Health monitoring using the M5Stack Mini Heart Rate Unit and Non-Contact Infrared Thermometer Unit and the Waylay IO platform.

Related Waylay articles

Hardware components

M5Stack Core2 ESP32 IoT Development Kit

M5Stack Mini HUB Unit 1 to 3 HUB

M5Stack Mini Heart Rate Unit MAX30100 Module Sensor

M5Stack NCIR Unit Contactless Temperature Sensor Module (MLX90614)

Software apps and online services


M5Stack M5Burner




In biology, homeostasis is defined as the state of stable internal, physical, and chemical conditions maintained by living systems. This is the condition in which an organism functions optimally and includes many parameters, such as body temperature, heart rate, fluid balance, blood oxygen saturation, and many more, being kept within certain limits that define a homeostatic range. The sole purpose of the medical field is to ensure the homeostasis of the human organism and technology has gone to great lengths to make that possible.

Healthcare monitoring systems in hospitals and other healthcare centers have gone through significant growth and portable healthcare monitoring systems are becoming of great interest today, as the emergence of IoT technologies facilitates the transition from face-to-face consulting to telemedicine.

In this tutorial, you will learn how to gather health parameters using an IoT device and store them in the cloud and showcase them in a neatly organized dashboard.

Healthcare Monitoring System Using M5Stack and Waylay IO

Hardware requirements

For this tutorial, we have decided to use the M5Stack Ecosystem because it offers the possibility of building such a system without prototyping specific tools, such as a soldering iron or prototyping cables. The ”heart” of this project is the M5Core2, an IoT development kit based on the ESP32 microcontroller. This ecosystem allows you to connect the provided modules through a GROVE port to the M5Core2, allowing fast deployment of hardware.


To showcase the use of IoT in Healthcare monitoring, we have picked the Mini Heat Rate Unit, based on the MAX30100 chip, with the possibility to measure the oxygen saturation in the blood and the heart rate of the patient. Another key parameter for an organism’s homeostasis is the temperature, which we have decided to record using a Non-Contact Infrared Thermometer Unit, based on the MLX90614 sensor. It allows the user to measure the surface temperature of the human body without having to touch them physically. If you want to read both sensors at the same time even if you trigger them separately you must use a 1 to 3 HUB Expansion Unit to connect both of them to the M5Core2.

Non-Contact Infrared Thermometer Unit, 1 to 3 HUB Expansion Unit and Mini Heart Rate Unit

Wire connections

  • Connect the 1 to 3 HUB Expansion Unit to PORT A of the M5Core2 (the red port near the USB-C connector) using the Grove cable.
  • Connect the Mini Heat Rate Unit and the Non-Contact Infrared Thermometer Unit to the HUB Expansion Unit.


  • Install Thonny following the steps on the official website.
Thonny Python IDE
Thonny Python IDE

Setting up the device

  • Connect the M5Stack kit to your PC using the provided USB Type-C cable. The port name should appear on the top-left corner of the app (near COM).

On Linux, make sure your user is part of the dialout group by running:

 sudo adduser $USER dialout 

  • Launch M5Burner and download the UIFlow(CORE2). Click the Erase button, wait for it to finish, and then press the Burn button to upload the UIFlow(CORE2) firmware on the device. We have used 1.8.1_core2 . You will be prompted for the WiFi details that the device will use to connect to your local network. If the burn fails, change the baud rate to a lower one.
  • Now click on the Configuration box corresponding to UIFlow(Core2) and select App Mode from the dropdown in the provided screen and add the Wifi details if not present.
  • After it finished rebooting, you will be greeted by an initial screen with the UiFlow version in the top right.
  • Let's go ahead and set up the cloud solution!

Setting up the cloud solution

Register on Waylay if you have not already and login.

  • Go to Resources and add a resource. You can name it HealthMonitorDev. This resource is practically your device representation in the cloud where you will send the data.
  • Add a new property with the customer key and the Zalmotek value.
  • Add another property with the tags key and the [ "HealthMonitor" ] value.
  • Go to Webscripts in the left main menu and add a new one. Name it something like HealthMonitorIngestion and add the following details in the body:
 async function handleRequest (req, res) {
  if (!req.body) {
    // No body found

  // Parse body if needed
  let payload = req.body
  if (typeof payload === 'string' || payload instanceof String)
    payload = JSON.parse(payload)

  You can do some processing of the payload over here.

  // Post values to our resource = ''
  await'replace_with_resource_id', payload, { store: true, forward: true })
    .catch(e => console.error(e.message))


Be sure to replace the replace_with_resource_id placeholder with the actual resource_id from the above step. Navigate to the resource page to get it. Ours is something like be416e6c-7448-4012-a878-c067352e9348. Press Save once you have pasted the correct details.

Programming the device

  • Go to the GitHub repository of this project (also present in the Code block of this tutorial) and download the zip file containing all necessary code and unpack it in a folder (or use the git command-line interface to do the same thing like a pro).
  • Launch Thonny and from Run -> Select interpreter set up the interpreter to MicroPython (ESP32) and while at it pick the device port.
  • Make sure the M5Stack is connected and displaying the initial screen, click on the Shell text field and press CTRL+C a few times or press on the STOP button to connect to the device. Once you see the >> symbol, you can access the files on the device. Go to View and select Files to set up your workspace. Navigate to the folder that you have unpacked at the first step. Then go to the file provided in this tutorial and edit the URL in the SendPOST() function with the URL of your Webscript. You can find it on, below the name of your Webscript. Click it to copy it to the clipboard (make sure the secret is included).
  • Select all the files from the folder downloaded from GitHub by holding Shift and clicking the files ( , and the 2 folders custom, res, files provided in this tutorial, exclude the Readme file, right-click on the menu icon (3 horizontal lines as shown below) and press Upload to /flash, press ok and you are set. Confirm the files being overwritten.
  • At this point be sure to have all the sensors connected as instructed before or else the program will hang on a white screen.
  • Reboot the M5Stack by pressing the down-side button, the one near the sd card slot (the screen will shut down and refresh). The device will connect to the WiFi network and automatically run the file.
  • Now let's test it! Place your finger on the Mini Heat Rate Unit and touch the heart icon on the display. You'll see your heart rate and blood oxygen level on the screen. And to measure your temperature, place your hand in front of the NCIR Thermometer Unit and touch the thermometer icon on the screen. No need to actually touch the sensor as it is a non-contact sensor!

Here's a short demo of the system:

And here is the graphical interface of the system:

Health Monitor Interface

Setting up an alarm

Alarms are a useful function through which you can get notified when the monitored values reach unwanted levels.

  • Select the Templates field from your user console and click on the Add Template button.
  • To create a basic alarm flow, we will be adding the necessary blocks from the blocks menu and then configure them.
  • Add a Stream block, uncheck execute on tick and check execute on data, then select your Resource of choice.
  • Add a Condition block, uncheck execute on tick and check execute on data, then select your Resource of choice. In the condition field write up the condition in the following format:

Ours looks like this:

 ${} > 150 
  • Add another Condition block with the following condition:
 ${} <90 
  • In our example, the metrics you can choose from are the ones defined in the DataMap variable in HeartRate and SPO2 (blood oxygen level).
  • Add a Create Alarm block, uncheck execute on tick and check execute on data, and select your Resource of choice. Also fill in your alarm text, your desired alarm type (CRITICAL, MAJOR, MINOR, or WARNING), and create an alarm type.
  • Click on the Save button and choose a name for your template.
  • Now that you have returned to the Templates menu, select the previously created template and click on Create Task.
  • Chose a name for your task, select the Resource choosing Reactive mode and click on Create Task.
  • Now the Task is created and when the condition is met, an alarm will be triggered and it will be displayed in the Alarms field of your console and also in your dashboard linked to the same Resource as the Alarm.

What’s next?

We have a series of tutorials with other use cases that you could learn from and further sharpen your IoT skills or you could start your very own project.

If you have any further questions, reach out to us via the comments!

Github Repository