Skip to main content

Nowadays a great number of people who want to maintain their heart’s pulse-rate under a certain value, this might be because they have had a heart attack in the past, or other health problems involving their heart, or because they practise some kind of sport and want to keep a low pulse-rate while being exercising and competing.

This project aims to write a script which will measure the user’s heartbeats, so when the pulse-rate overtakes a maximum value (optima), a piezoelectric will start buzzing intermittently until the user’s pulse-rate drops below this maximum value. This function is called Heart-rate mode.  The buzzer can be muted with a push-button, and the RGB led will turn blue.

Additionally, a push-button allows switching from the Heart-rate mode to the Temperature mode. This function measures the temperature of the user and turns on an RGB-led with a  colour depending on the measured temperature, green if the temperature is below 37ºC, yellow from 37ºC to 38ºC, and red for temperatures greater than 38ºC. Because of the worldwide alarm caused by the CORONAVIRUS at present, this function is currently really useful.

Glossary:

Pulse: a short period of energy that is repeated regularly.

Pulse-rate or Heart rate: the frequency at which the heart beats. It is measured as the number of beats per minute (bpm).

Heartbeat: heart’s complete action of pumping.

 

1. Electronic circuit design

The components needed to develop the project are the following ones:

  • PIC16F877A microcontroller from Microchip
  • PICDEM 2 PLUS board from Microchip
  • SEN-11574 Pulse Sensor from Sparkfun Electronics
  • LM35DZ Temperature Sensor from Texas Instruments
  • ZSM-T5050-RGB from JKL Components Corporation

Microcontroller

The control circuit is based on the PIC16F877A from Microchip, which is going to be connected to the PICDEM2 PLUS board. We will be using both RA4 and RB0 pins as push-buttons and the piezoelectric buzzer (connected to the pin RC2) of the board.

Pulse sensor

The SEN-11574 is an optical heartbeat-sensor that has an amplifier and a circuit to cancel the noise (its connections are shown in the picture below). This component is going to be connected to a voltage of 5V (Vcc+) and to the ground, returning an analog signal which represents the heartbeats (see Figure 1). This analog signal will be connected to RA0.

fig19_811ba1ee7888b2dd7e5f755b538aee510bdc539e.png

 

Figure 1: Connections of the SEN-11574 pulsometer.

Temperature sensor

The LM35DZ is an integrated circuit that gives an analog response that changes linearly with temperature. For that, the circuit must be connected to Vcc+ (5V) and to GND, and the output analog-signal will be connected to RA1. The output signal is given through the terminal Vout (see Figure 2) according to eq. 1

eq1_3bd7ba3b112dcf9849a1210f950a7a330fa83b93.pngeq. 1

fig29_32bfa24017e6535f0bd8fc989677ae32592ac79d.png

Figure 2: Connections of LM35DZ temperature sensor

RGB LEDs

The SM-T5050-RGB is the combination of the anodes of three different-coloured LEDs (Red, Green and Blue). This circuit needs a connection to ground (GND), and each led is connected to one separate digital pin to obtain different colour combinations: Red to RD0, the Green to RD1, and the Blue to RD2.

These LEDs work with tensions between 1.5V and 3V, but as the microcontroller is working with 5V, we must introduce some resistors to avoid burning the LEDs (we can see these resistors in Figure 3).

fig37_c9aa52573392587085c00656b1c43be1ba791a1f.png

 

Figure 3: RGB mounted in the printed circuit board with the resistors

To sum up, the connections between all these components are represented in Figure 4:

fig46_e2de1b3a988b2708fbfd0434ea6de30dbad93dfa.png

 

fig4_2_a7787af33b62b55277ad5f69194ebacf7e16e6fe.png

 

Figure 4: Schematic representation of the connections of the modules with the PIC16F877A microcontroller.

2.Programming environment

This section describes the number of pins of the microcontroller that are used and the configuration of the different hardware modules.

table12_5793d0854ed3b45730971bf4cf2d9a0f92b16841.png

 

The microcontroller has been programmed using the Integrated Development Environment (IDE) MPLAB 8.92 and the ICD2 debugger as a depuration tool. The programming language used for this project is C by means of the HI-tech compilation tool. All the code has been attached at the end of the article but some of the main microcontroller integrated hardware used in the project is described below.

Timer0 and A/D converter

The TMR0 is used to set a new A/D conversion each 10ms, so it is working as a timer. When the TMR0 overflows, the bit T0IF will cause an interruption that will lead to a new A/D conversion by setting to 1 the bit GO/DONE#.

The A/D converter “takes” the analog value of RA0 or RA1, depending on the pulsometer’s mode: RA0 for the Heart-rate mode; and RA1 when the temperature mode is selected. This is done with an internal multiplexer (the value of which is negated each time RB0 is pushed). This way we do not mix data coming from the thermometer with that coming from the pulse sensor and vice versa.

The digital result of the A/D conversion is a value of 10 bits, but we are only going to use 8 bits from the result: the 8 more significant in the Heart-rate mode, losing precision by getting a digital value of 8 bits because we have disregarded the two less-significant bits;  and the 8 less significant in the Temperature mode. Because we do not need such a great range (the temperature sensor can measure temperatures from 2ºC to 502ºC, but the temperature of a body has a low range of variation, normally going from 35ºC to 42ºC), so we can disregard the two more-significant bits without really losing any relevant data.

CCPWM module

This module will be used in the PWM-mode for the buzzer to emit an intermittent beep of 1kHz when the user exceeds the optimal heart-rate (beats-per-minute). The buzzer emits this 1kHz sound every 5 heart-pulses. The beeping can be muted by pressing RA4, and later unmuted in the same way.

For the PWM-mode we must use the Timer2. We want to emit a squared signal with a frequency of 1kHz (period of 1ms) and duty-cycle of 50%. If we set the pre-division-factor as 4, the post-divisor as 1 and the internal oscillator to 4MHz, then we obtain the equation:  eq21_b0c925e4e1f08daeba5c524de0d2c268f03bfd64.png

from which we calculate PR2=249. So the Timer2 resets when TMR2 reaches the value PR2+1=250.

Regarding the duty-cycle, the value of RC2/CCP1 (the buzzer) is 1 until the value of Timer2 reaches half of its period, that is 250/2=125, so we must set CCPR1L=125.

Interruptions

We must enable global and peripheral interruptions, as well as the particular interruptions from the A/D converter, from the push-button RB0 and from the Timer0. By using interrupts we assure proper timings and delays.

3. Measurement

Heart-rate mode

This function uses the buzzer to warn the user if their heart-rate is faster than a certain heart-rate, that can be modified, which is called optima. The pulse sensors measure is converted to a digital value every 10ms. This digital value is stored in the variable pulse, and compared with ref (that is equivalent to the 70% of the total measure-range of the pulse sensor; this range goes from 0V to 5V. As the resolution of the digital value is of 8 bits, then the 70% would have the hexadecimal value 0xB4, which is equal to 180 in decimal, so ref=180.

The comparison between optima and the measured heart-rate is performed every 5 heartbeats (a complete contraction of the heart), that is, we have to count the time that passes starting from the first peak (or pulse) to the sixth peak (or pulse). When the sixth peak has been detected, we proceed to compare the period of 5 heartbeats with the period of 5 optimal heartbeats (optima). Measuring this way reduces possible errors due to fast variations, calculation delays, etc.eq32_fce4f465b27343061460cea7ee148e923b772038.pngThe Contador register stores how many times has the TMR0 overflowed, that is, how many times the TMR0 has counted 10ms. 

eq4_f9acf89c63ca4b5d793a847d701f944708859aba.pngTherefore, optima is the equivalent value of the time it takes a heart at 100bpm to complete 5 heartbeats (see Figure 5).

fig57_a179019129685721b8ccab544e57cdad834081cb.png

 

Figure 5: Heartbeat signal representation

Temperature mode

Pushing RB0 the user can change from Heart-rate mode to Temperature mode or vice versa.

In this mode, environmental temperature is measured and the result is given with a precision of 1ºC. The operation to calculate the temperature from the digital value (temp) is the next one:eq5_0ccd288b8ce1549506cb2ee28b1c2ecbda4bb349.pngThe user can easily know if they have a fever or not by a simple colour-system. Under 37ºC, they have no fever, the green led turns on,  between 37ºC and 38ºC, red and green LEDs turn on simultaneously, emitting a yellowed-orange light; and if the temperature surpasses 38ºC, only the red led emits light.

Downloads

MikelHualde has not written a bio yet…
DesignSpark Electrical Logolinkedin