Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation: the Raspberry Pi 5, the pulse sensor, the ADS1115, the OLED and the BEAT LED

Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation, the sixty-eighth project of our IoT Projects series. If you have searched for a Raspberry Pi heart rate variability project, a pulse sensor with an ADS1115, how RMSSD and SDNN are calculated, or a Proteus simulation of a heart monitor, here is a complete one. A fitness band shows a heart rate; this monitor goes one step further and looks at the time between every two beats. From those intervals it measures the variability of the heart rhythm, works out the breathing rate without a breathing sensor, finds premature beats, ignores the beats a moving finger fakes, and measures how fast the heart rate recovers after exercise.

The heart does not beat like a metronome, and the small changes from one beat to the next carry real information: they grow and shrink with each breath, they fade when the heart works hard, and an irregular pattern can point to an arrhythmia. Measuring them needs timing about ten times finer than the readings themselves. In this tutorial, we will go through the circuit, see what a pulse sensor measures, read it with an ADS1115 every 10 ms, find the one moment of each pulse that the noise moves least, sort the intervals into normal beats, premature beats and motion, calculate RMSSD and SDNN with worked examples, read the breathing from the heart, fit the recovery after exercise, and walk through the Python program. Then we run the simulation: a calm rest, an arrhythmia, a shaken finger and a burst of exercise. At the end, you can download the project with the program and every library file. This is a learning project, not a medical device.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the pulse sensor HRV monitor on Raspberry Pi 5 in Proteus simulation:

Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation: the Raspberry Pi 5, the pulse sensor, the ADS1115, the OLED and the BEAT LED
Figure: The HRV monitor in a Proteus simulation: the Raspberry Pi 5 timing every beat.
Pulse Sensor HRV Monitor on Raspberry Pi 5: the working Proteus simulation, an animated view of the project's main steps
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This HRV Monitor Do?

  • Reads the pulse: a pulse sensor on a fingertip gives a voltage that rises with every heartbeat; an ADS1115 converts it 860 times a second and the Raspberry Pi 5 reads it every 10 ms.
  • Times every beat to about a millisecond: the moment the pulse is half-way up its rise, found between two readings.
  • Sorts the intervals: normal beats, premature beats with their pause, missed beats and the beats a moving finger fakes; only the normal ones count.
  • Measures the variability: the heart rate, SDNN and RMSSD over the last 30 seconds, and whether the rhythm is regular.
  • Reads the breathing from the heart: the intervals swing with every breath, and the monitor counts the swings.
  • Measures the recovery: after exercise, how far the heart rate falls in 30 and 60 seconds, and the time constant of the fall.
  • Shows it all: a BEAT LED on every pulse, a 128x64 OLED, and a dashboard with a picture of the intervals on a laptop or a phone.

It is a great project for learning signal timing, simple and robust detection, a little statistics and a little physiology in one place. In the simulation, the pulse sensor's pop-up is the person: a heart rate slider, a breath every 4 seconds that the heart follows, an ARRHYTHMIA button with premature beats, SHAKE for a moving finger, and AFTER EXERCISE for a heart rate that jumps and recovers. Every effect comes from the model's own rules, so the monitor's numbers can be checked against them.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEP Pi runtime.

The parts of the HRV monitor and their library posts
PartProteus deviceLibrary postConnection
Raspberry Pi 5RASPBERRY PI 5Raspberry Pi 5 Library for ProteusPI1, hrv_monitor.py, Ethernet 192.168.1.51
Heart beat pulse sensorPULSESENSORADVTEPHeart Beat Sensor Library for ProteusU2: SIG to A0 of U1, VCC +3.3V, GND
ADS1115 16-bit ADCADS1115ADVTEPADS1115 ADC Library for ProteusU1, I2C1 at 0x48, VDD +3.3V
SSD1306 OLED 0.96" 128x64OLED12864WHITEADVTEPOLED SSD1306 Library for ProteusU3, I2C1 at 0x3C
SMD LED redLEDSMDREDTEPSMD LED LibraryD1, the BEAT LED, on GPIO17 (pin 11)
SMD resistorRESISTORSMD1206TEPSMD Resistor LibraryR1 220 ohm for the LED
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the HRV Monitor: the Circuit

HRV monitor Proteus simulation circuit: Raspberry Pi 5, a pulse sensor, an ADS1115, a 128x64 OLED and a BEAT LED
Figure: The complete circuit of the HRV monitor on an A3 Proteus sheet.
The connections of the HRV monitor
PartPinsRaspberry Pi 5 / supply
U1 ADS1115SDA / SCLGPIO2 (pin 3) / GPIO3 (pin 5)
U1 ADS1115VDD / GND / ADDR+3.3V / GND / GND (address 0x48)
U1 ADS1115A0SIG of the pulse sensor
U2 pulse sensorSIG / VCC / GNDA0 of U1 / +3.3V / GND
U3 OLEDSDA / SCL / VCCGPIO2 / GPIO3 / +3.3V
D1 BEATanodeGPIO17 (pin 11) through R1 220 ohm

The Raspberry Pi has no analog input, so the ADS1115 reads the pulse for it and shares the I2C bus with the OLED. The pulse sensor runs from 3.3 V, the same supply as the ADC: its output follows the supply, so at 3.3 V it rests near 1.65 V and swings by about half a volt with each beat, comfortably inside the ADS1115's +-4.096 V range, where one count is 125 uV. A sensor on 5 V could swing above 3.6 V, more than an ADS1115 on 3.3 V may take on its inputs. The sensor's three pins sit on the bottom edge of its round board; its supply pin needs a real +3.3V terminal, because it feeds the sensor's light and amplifier in the model. The red BEAT LED flashes for 120 ms on every beat the Pi finds.

How the HRV Monitor Works

What a Pulse Sensor Measures

A pulse sensor shines green light into the fingertip and measures how much comes back. Each heartbeat pushes a wave of blood into the small arteries, the tissue absorbs a little more light, and the sensor's amplifier turns that into a rise of its output. The technique is called photoplethysmography (PPG). The wave has a steep upstroke when the blood arrives, a peak, and a slower fall with a small shoulder, the dicrotic wave. In the sensor's model the upstroke is a half-cosine 130 ms long at 75 BPM, about 150 counts high on its 1024-count scale. At 3.3 V that is 0.48 V, so the steepest part of the rise climbs at 0.48 x pi / (2 x 0.13) = 5.8 V/s.

Reading the Pulse Every 10 ms

The ADS1115 runs in continuous mode at 860 samples a second, so it always holds a result less than 1.2 ms old, and the Pi reads it every 10 ms, a 2-byte read on the I2C bus. Ten milliseconds is plenty to see every beat. It is not enough to time the beats well, if each beat is simply taken at the reading that crossed a threshold: then every interval is uncertain by 10 ms, more than the effect we want to measure, because the breathing moves the intervals by only about 24 ms at rest. The monitor needs a moment of the wave that it can place between two readings.

Finding the Beat: Half-Way up the Upstroke

The first idea is the steepest point of the upstroke, a classic choice. The program tried it first and an offline copy of the sensor's model showed why it fails here: a half-cosine's slope has a flat top, it changes by only 3 % within 10 ms of the peak, while the sensor's noise moves a slope measured over 20 ms by about 0.5 V/s, nearly 9 %. The fitted peak wandered by 6.7 ms rms. The better moment is the one where the signal itself crosses half-way from the foot of the upstroke to its top. That is where the signal climbs fastest, so a little noise in the voltage moves the moment very little. Worked example: an error of 3 mV, about one count of the sensor, divided by 5.8 V/s, is 0.5 ms. Between the two readings around the crossing the wave is almost a straight line, so a line through them gives the moment. The same offline test gave 0.58 ms rms. To find the upstrokes, the program watches the slope between readings 20 ms apart: an upstroke starts above 35 % of the beats' own steepest slope, and the next one can start only after the slope has fallen under 15 % and 250 ms have passed. The threshold follows the beats: after each beat it moves 20 % of the way to that beat's slope.

Sorting the Intervals

An interval between two beats is not always a normal one. A premature beat comes early, and the heart then waits longer before the next one, so the pair adds up to about two normal intervals: in the sensor's arrhythmia, 0.62 x 800 = 496 ms and then 1.38 x 800 = 1104 ms, together 1600 ms, exactly two. The program holds each interval until the next one arrives: a short one, under 80 % of the median of the last normal intervals, followed by a long one, over 115 %, that add up to two intervals within 20 % is a PREMATURE BEAT, and both are left out. An interval of 1.7 normal ones or more is a MISSED beat. A moving finger makes swings far bigger than any pulse, and it gives itself away by its falls: a pulse falls at most about 0.6 times as fast as it rises, so a fall steeper than 0.9 times the beats' rise is MOTION, and every beat until 1 s after the last steep slope is left out. Only the NORMAL intervals, called NN intervals, count for the variability.

SDNN and RMSSD

The two standard measures of heart rate variability are SDNN, the standard deviation of the NN intervals, and RMSSD, the root mean square of the successive differences between them. SDNN sees every change, slow ones included; RMSSD sees only the change from beat to beat, which mostly comes from the vagus nerve and the breathing. Medical HRV uses 5-minute recordings; fitness devices use short windows, and the program uses the last 30 seconds. Worked example with the model at rest: the intervals are 800 ms x (1 + 0.03 sin of the breath's phase), and a breath lasts 4 s, five beats, so the phase moves 72 degrees from one beat to the next. The intervals swing by 24 ms, and SDNN = 24 / square root of 2 = 17.0 ms. A successive difference of a sine sampled 72 degrees apart has the amplitude 24 x 2 sin(36 degrees) = 28.2 ms, so RMSSD = 28.2 / square root of 2 = 19.9 ms.

Regular or Irregular?

The program compares each of the last 16 NN intervals with the mean of its two neighbours and takes the root mean square of the differences, as a percentage of the mean interval. A steady rise or fall of the heart rate cancels out in that comparison, which matters after exercise. At rest the breathing gives 24 x (1 - cos 72 degrees) = 16.6 ms of amplitude, 11.7 ms rms, only 1.5 % of 800 ms. The model's arrhythmia moves each interval at random by up to 22 %: a standard deviation of 0.22 x 800 / square root of 3 = 102 ms, and against two neighbours 1.22 times that, 124 ms, about 15 %. The line between them is drawn at 8 %: above it the rhythm is IRREGULAR, and the variability numbers are no longer about the breathing.

The Breathing in the Heart Rate

The intervals lengthen as we breathe out and shorten as we breathe in; physiologists call this respiratory sinus arrhythmia, and it means the heart rate carries the breathing rate. The program subtracts from each NN interval the mean of the five around it, which removes slow changes, and counts how often the result crosses zero upwards, with a 2 ms margin against noise. Breaths per minute = 60 x (crossings - 1) / the time from the first crossing to the last. With the model's breath every 4 s, that should be 15 per minute. The breathing is shown only while the rhythm is regular and the rate is under 100 BPM, because at a fast rate the swing fades, in the model as in real life.

Heart Rate Recovery

How fast the heart rate falls after exercise is a well-known sign of fitness: the drop in the first minute, HRR60, is usually more than 12 BPM in a healthy adult. The program keeps a resting rate, the 30-second mean while the rhythm is calm. A 4-beat mean more than 25 BPM above it means EXERCISE; the program follows the peak, and once the rate has fallen 5 BPM below it, the recovery has started. It records the fall 30 s and 60 s after the peak and fits the recovery: ln(heart rate - resting rate) against the time is a straight line whose slope is -1 divided by the time constant. Worked example with the model: AFTER EXERCISE adds 70 BPM x e to the power -t/25 s x (1 - e to the power -t/1.5 s). The boost peaks at about 4.3 s at 70 x 0.842 x 0.943 = 55.6 BPM, so 75 becomes 130.6 BPM; 60 s after the peak the boost is 70 x e to the power -64.3/25 = 5.4 BPM, 80.4 BPM in all, an HRR60 of about 50 BPM, and the fit should find 25 s.

Keeping the Timing Clean

One more trap sits on the I2C bus. A full OLED frame is 1024 bytes, about a tenth of a second on the bus at 100 kHz; written at once, it would stop the readings for ten steps every second and spoil the beats it hit. So the program prepares a frame once a second and sends it 32 bytes at a time, one piece after each reading, about 3 ms that fit easily in the 10 ms step. A whole frame takes 0.32 s, and the readings never stop.

The Python Code Explained

The program is hrv_monitor.py, plain Python 3 with lgpio for the I2C bus and the LED, threading, and http.server for the dashboard. No other library is needed: it runs the same way on a real Raspberry Pi 5 with Raspberry Pi OS. The timing constants at the top:

STEP = 0.010                                                    # a reading every 10 ms
RISE, REARM = 0.35, 0.15                                        # a beat starts above 35 % of the beats' slope, re-arms under 15 %

The ADS1115 in continuous mode, A0 against ground, +-4.096 V, 860 samples a second:

        lgpio.i2c_write_i2c_block_data(self.h, 0x01, [0x42, 0xE3])  # AIN0 to GND, +-4.096 V, CONTINUOUS; 860 SPS, no comparator

The slope at each reading, over the readings 10 ms before and after it:

        (t0, v0), (tm, _), (t2, v2) = self.buf[-3:]             # the slope at the middle reading, over 20 ms: half the noise
        slope = (v2 - v0) / (t2 - t0)

A fall that no pulse can make marks the finger as moving:

        if slope < -FALL * self.slope_ref or slope > MOTION * self.slope_ref:   # a pulse never falls this fast: the finger moved

An upstroke starts above the threshold, and not too soon after the last beat:

        if slope > RISE * self.slope_ref and (self.last_beat is None or tm - self.last_beat > REFRACTORY):

The beat: half-way from the foot to the top, by a line between the two readings around it:

        level = (foot + top) / 2
            if va < level <= vc:
                tb = ta + (level - va) / (vc - va) * (tc - ta); break

A premature beat and its pause, recognised by their sum:

        if pms < 0.8 * med and ms > 1.15 * med and abs(pms + ms - 2 * med) < 0.2 * med:

SDNN and RMSSD from the NN intervals of the last 30 seconds:

        sdnn = math.sqrt(sum((m - mean) ** 2 for m in ms) / (len(ms) - 1))
        dif = [ms[k + 1] - ms[k] for k in range(len(ms) - 1)]       # (successive NN only: no gap between them)
        rmssd = math.sqrt(sum(d * d for d in dif) / len(dif))

The rhythm: each interval against its neighbours:

        dev = [last16[k] - (last16[k - 1] + last16[k + 1]) / 2 for k in range(1, len(last16) - 1)]   # (a steady rise or fall of

The breathing: each interval minus the mean of the five around it:

                d = ms[k] - sum(ms[k - 2:k + 3]) / 5

The recovery's time constant from the slope of the straight line:

                r['tau'] = -1 / b

The OLED, 32 bytes after each reading:

            lgpio.i2c_write_i2c_block_data(self.h, 0x40, self.buf[self.k:self.k + 32])

The reading loop keeps its own schedule, 10 ms after 10 ms, and starts afresh from now if it ever falls behind. The web server runs in the main thread: / is the dashboard, /tacho.bmp a 240 x 100 picture of the intervals of the last 60 s (normal green, premature and pause red, missed amber, motion grey), /reset starts again and /data gives everything as JSON. Every event goes to the terminal with its time.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
  2. Open Pi-5-HRV-Monitor.pdsprj from the Proteus Simulation folder. Keep hrv_monitor.py and the DLL files next to it.
  3. Press Play. The finger is on the sensor at a resting 75 BPM; after about 15 s the OLED shows RMSSD, SDNN and the breathing.
  4. On the pulse sensor's pop-up (U2) press ARRHYTHMIA, then turn it off and press SHAKE.
  5. Press AFTER EXERCISE and wait a minute for the recovery.
  6. Open the Laptop or the Mobile WiFi Monitor and press Go for the dashboard.

Simulation Results: the HRV Monitor in Proteus

Here is the run that made the screenshots of this tutorial, 166 seconds of simulation: a calm rest, an arrhythmia, a shaken finger and a burst of exercise with its recovery. The times are the program's own clock, as it printed them in the Raspberry Pi's terminal; the sensor's pop-up shows the true heart, so every number can be checked.

At Rest: the Breathing in the Intervals

After 36 seconds at a resting 75 BPM the OLED reads RMSSD 20 ms, SDNN 17 ms and a breathing rate of 15.0 per minute, and the dashboard gives the decimals: RMSSD 20.0 ms, SDNN 17.1 ms, from 38 NN intervals in 30 s. The worked examples above predicted 19.9 ms, 17.0 ms and 15 from the model's own breath, so the timing really is good to about a millisecond: a beat timed only to the nearest 10 ms reading would have added several milliseconds of RMSSD of its own. The dashboard's picture shows the intervals as a clean wave, five beats to a breath. The ADS1115's pop-up confirms the settings: continuous conversions of AIN0 at 860 samples a second on the +-4.096 V range, about 100 reads a second from the Pi.

The sensor's pop-up shows one more thing worth a sentence: its "Sketch: no pulse". That readout belongs to the library's own Arduino demo, which looks for a fixed level of 550 counts on a 5 V board. At 3.3 V the whole wave sits below that level, and a fixed threshold never fires; the Pi's threshold, which follows the beats' own slope, finds every one.

The HRV monitor Proteus simulation at rest: the Raspberry Pi 5, the OLED with RMSSD and SDNN, the BEAT LED lit
Figure: At rest: the BEAT LED flashing on every beat.
Heart beat sensor pop-up in the Proteus simulation: 77 BPM at rest, the PPG wave of the last 5 seconds
Figure: The pulse sensor at rest.
OLED pop-up in the Proteus simulation: HR 74 BPM REGULAR, RMSSD 20, SDNN 17, BREATH 15.0 /MIN
Figure: The OLED at rest.
ADS1115 pop-up in the Proteus simulation: continuous conversions of AIN0 at 860 SPS, about 1.54 V
Figure: The ADS1115 reading the pulse.
Laptop WiFi Monitor in the Proteus simulation: RMSSD 20.0 ms, SDNN 17.1 ms, breathing 15.0 per minute
Figure: The dashboard: the breathing as a wave of intervals.

An Arrhythmia: Premature Beats

ARRHYTHMIA on the sensor's pop-up at 47 s. At 48.4 s the first one: "PREMATURE BEAT: 489 ms after the last (61 % of 801), then a 1084 ms pause - together 1.96 intervals". Three more follow, at 2.05, 2.01 and 2.09 intervals: the model makes a premature beat at 0.62 of an interval and a pause of 1.38, two intervals together, and the program recognises every one by that sum. The other beats of the arrhythmia wander by up to 22 %, and at 58.9 s: "RHYTHM IRREGULAR - the intervals stray 9.9 % from their neighbours". The OLED shows IRREGULAR and PB 3 at that moment, and BREATH -- , because the breathing cannot be read from an irregular rhythm. In the dashboard's picture each premature beat is a red pair, a short interval below and its pause above.

The HRV monitor Proteus simulation during an arrhythmia: the OLED showing IRREGULAR and the premature beats
Figure: An arrhythmia.
Heart beat sensor pop-up in the Proteus simulation: ARRHYTHMIA now 71 BPM, the irregular beats on the PPG
Figure: The sensor's arrhythmia.
OLED pop-up in the Proteus simulation: HR 68 BPM IRREGULAR, RMSSD 99, SDNN 70, PB 3
Figure: The OLED: IRREGULAR.
Laptop dashboard in the Proteus simulation: IRREGULAR, premature 4, the red pairs of the premature beats
Figure: The dashboard: each premature beat a short interval and a pause.

Regular again at 68 s, and at 74.5 s the program agrees: "RHYTHM REGULAR". RMSSD and SDNN stay high for a while longer, because the 30-second window still holds the irregular intervals; the next screenshot, ten seconds later, shows RMSSD 109 ms for that reason.

A Shaken Finger

SHAKE at 77.5 s: for 2 seconds the model swings the signal by up to a few hundred counts, much more than a pulse. Within half a second: "MOTION - a slope of -6.5 V/s against the beats' 5.9: the beats until 1 s after it are left out". A pulse never falls that fast, 1.1 times its own rise, so the fall gives the movement away. Four intervals were left out and none of the swings was counted as a beat; the sensor's own demo sketch, with its fixed threshold, would have counted false beats here.

Heart beat sensor pop-up in the Proteus simulation: MOTION, the finger shaking, the swings on the PPG
Figure: The finger shaking: the swings on the pulse.
OLED pop-up in the Proteus simulation: MOTION 4, the beats of the movement left out
Figure: The OLED: four intervals left out.

Exercise and Recovery

AFTER EXERCISE at 87 s, and the heart rate climbs. At 89.4 s: "EXERCISE - the heart rate 100 BPM, 26 above the resting 74". The rate peaks at 131 BPM at 92.1 s, the program sees it falling and prints "RECOVERY from a peak of 131 BPM". The OLED now shows RMSSD 35 ms and SDNN 157 ms: SDNN counts the big fall of the rate as variability, while RMSSD, which only looks from beat to beat, stays modest. That is exactly why the two measures are used together.

The HRV monitor Proteus simulation after exercise: the OLED showing 118 BPM and RECOVERY
Figure: After exercise.
Heart beat sensor pop-up in the Proteus simulation: AFTER EXERCISE now 113 BPM, faster and stronger beats
Figure: The sensor after exercise.
OLED pop-up in the Proteus simulation: HR 118 BPM REGULAR, RMSSD 35, SDNN 157, RECOVERY
Figure: The OLED: RECOVERY.
Laptop dashboard in the Proteus simulation: the recovery from a peak of 131 BPM, the intervals rising again
Figure: The dashboard: the intervals rising again.

At 122.9 s: "HRR30: 39 BPM in 30 s (131 to 92 BPM)". At 153.4 s: "HRR60: 50 BPM in 60 s (131 to 81 BPM); the recovery time constant 27.4 s from 83 beats". The worked example predicted an HRR60 of about 50 BPM, and that is what the program measured. The time constant came out at 27.4 s against the model's 25 s: in the last half minute the rise above the resting rate is only a few BPM, and the breathing's swing, which comes back as the rate falls, is a large part of it. By then the breathing reads 15.3 per minute again and RMSSD is back to 16 ms.

The HRV monitor Proteus simulation: the recovery measured, HRR60 50 and TAU 27 S on the OLED
Figure: The recovery measured.
Heart beat sensor pop-up in the Proteus simulation: the rate back near 78 BPM after the exercise
Figure: The sensor recovering.
OLED pop-up in the Proteus simulation: HR 79 BPM, RMSSD 16, BREATH 15.3 /MIN, HRR60 50 TAU 27 S
Figure: The OLED at the end.
Laptop dashboard in the Proteus simulation: the recovery, peak 131 BPM, HRR30 39, HRR60 50, tau 27.4 s
Figure: The dashboard: the recovery.
Mobile WiFi Monitor in the Proteus simulation: the HRV dashboard with the recovery
Figure: The phone.
Raspberry Pi 5 terminal in the Proteus simulation: the premature beats, the rhythm, the motion and the recovery
Figure: The terminal: every event of the run.
The results of the HRV monitor simulation
WhatThe programThe model
Rest, 75 BPMRMSSD 20.0 ms, SDNN 17.1 ms, 15.0 breaths a minute19.9 ms, 17.0 ms, 15
Premature beats4 found, 1.96 - 2.09 intervals with the pause0.62 + 1.38 = 2.00
ArrhythmiaIRREGULAR at 9.9 %intervals +-22 %
ShakeMOTION, 4 intervals out, no false beat2 s of motion
Exercisepeak 131 BPM, HRR30 39, HRR60 50 BPMpeak about 131, HRR60 about 50
Recovery time constant27.4 s from 83 beats25 s
Simulation166 s of simulation-

Download the Project Files

Click the button below to download Pulse-Sensor-HRV-Monitor-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 14.5 MB, without the source code of the models):

Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation V1.0
  • Proteus Simulation: Pi-5-HRV-Monitor.pdsprj, hrv_monitor.py and copies of the models.
  • Python Code: hrv_monitor.py, the program.
  • Proteus Library Files: the LIB files of the Raspberry Pi 5, the pulse sensor, the ADS1115, the OLED, the SMD LED and resistor and the two WiFi Monitors.
  • Proteus Model Files: the DLL models and the TEPPi folder (Python and the TEP Pi runtime).
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

Edit hrv_monitor.py beside the project; PI1 runs the file named in its PROGRAM property, so a change takes effect at the next Play. The step, the thresholds, the motion limits, the window and the irregularity line are at the top. On a real Raspberry Pi 5, run it with python3 after enabling I2C.

Ideas to Extend the Project

  • Add the frequency-domain measures: the power of the intervals at the breathing frequency (HF) and below it (LF), from a 2-minute window.
  • Log the intervals to a CSV file and compare a calm minute with a minute after climbing stairs.
  • Guide the breathing: flash the LED at 6 breaths a minute and watch RMSSD grow, the idea behind HRV biofeedback.
  • Add a second sensor on the earlobe and measure the pulse transit time between the two.
  • Send the night's average RMSSD to a phone in the morning.
  • Replace the fixed 8 % irregularity line with a learned one, and test it on a recorded rhythm.

From Simulation to Real Hardware

  • Keep still and press lightly: a real PPG is far noisier than the model, and most errors come from movement and from pressing too hard.
  • Shield the light: sunlight and room lights flicker into the sensor; a dark sleeve over the finger helps.
  • Check the timing: Python on Linux is not a real-time system; keep the reading loop alone in its thread, and log any late reading.
  • Use the same supply: the sensor's output follows its supply, so power it from the ADC's 3.3 V and keep the input under 3.6 V.
  • Not a medical device: HRV depends on age, fitness, sleep and much more; use the numbers to learn, never to make health decisions.

Troubleshooting

  • No beats: SIG to A0 of the ADS1115; the sensor's VCC needs a real supply (+3.3V), not a net label.
  • The rate is twice the heart's: give the threshold the first 2.5 s to learn the beats' slope.
  • Everything says MOTION: keep the finger still; SHAKE lasts 2 s.
  • The OLED stays blank: SDA / SCL on GPIO2 / GPIO3, address 0x3C, VCC on 3.3 V.
  • Python does not start: the TEPPi folder must be in the MODELS folder.

Limitations of the Simulation

  • The pulse is the library's model: a clean wave with a little noise, a breath every 4 seconds, and rule-based arrhythmia, exercise and motion.
  • A real heart's variability has many sources; the model has the breathing and the arrhythmia only.
  • The network to the laptop and the phone is simulated inside Proteus.
  • Raspberry Pi is a trademark of Raspberry Pi Ltd; this project is not made or endorsed by them or by Labcenter. It is not a medical device.

So, that was all about the Pulse Sensor HRV Monitor on Raspberry Pi 5 - Proteus Simulation. I hope it helps you understand what a pulse sensor measures, how to time a beat ten times finer than the readings, how premature beats and a moving finger are recognised, what RMSSD and SDNN mean and where the breathing hides in the heart rate, all tested in a simulation before you try it on a real finger. More IoT projects with the ESP32 and the Raspberry Pi 5 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation