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
Before you start this example, install these MathWorks® products:
Simulink Support Package for Arduino Hardware
MATLAB Support Package for Arduino Hardware
We recommend completing these examples:
Getting Started with MATLAB Support Package for Arduino Hardware (MATLAB Support Package for Arduino Hardware)
REES52 Heart Rate sensor
Configure and Run Models on the Arduino Board
Open the arduino_heart_rate_sensor model.
On the Hardware tab, click Hardware Settings to open the Configuration Parameters dialog box.
Select the Hardware Implementation pane and select your Arduino hardware from the Hardware board parameter list. Do not change any other settings. Click OK.
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.
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.