Main Content

Heart Rate Sensor Using Arduino

This example shows how MATLAB Function is used in Simulink® models to read the analog voltage from a heart rate sensor. The MATLAB® function reads the analog voltage from a REES52 Heart Rate sensor connected to 'A0' pin on the Arduino® Uno board. Arduino Uno board can read voltage between 0 to 5V and returns a number in the range of 0-1023. The MATLAB Function block in the model returns this number. If you hold the sensor, the reading changes. Heart rate can be calculated based on the change in this reading.

A sample image with a heart rate sensor is as shown below.

The Heart rate sensor consists of three wires. The right-most wire (R) is connected to the analog pin, the middle wire (M) is connected to vcc and the left-most wire (L) is connected to ground.

  • R - A0

  • M - Vcc (5V)

  • L - GND

Prerequisites

We recommend completing the Getting Started with MATLAB Support Package for Arduino Hardware example.

Required Hardware

  • Arduino Uno

  • REES52 Heart Rate sensor

Configure and Run Models on the Arduino Board

  1. Open the arduino_heart_rate_sensor Simulink model.

  1. On the Hardware tab, click Hardware Settings to open the Configuration Parameters dialog box.

  2. Select the Hardware Implementation pane and select your Arduino hardware from the Hardware board parameter list. Do not change any other settings. Click OK.

  3. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start to run this model on the Arduino board.

  4. To view the sensor readings on the host computer, run the model using the Monitor and Tune feature. To do this, on the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune.

More About

MATLAB Function Block Basics block