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 hardware connections for R,M, and L, as shown in the above image assumes that the surface of the heart rate sensor with a heart symbol is facing the user. 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
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.
Click the Deploy to Hardware button 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, go to the Hardware tab and click Monitor & Tune.
MATLAB Function Block Basics (Simulink)