Heart rate monitors are widely used in healthcare, sports, and personal fitness to measure an individual's pulse rate in real time. Commercial devices often come with high costs and proprietary designs, but with the accessibility of microcontrollers like the PIC series, building a low-cost, functional heart rate monitor is entirely feasible. This guide provides an in-depth look at designing and constructing such a device using a PIC microcontroller, covering from component selection to programming and testing. Whether you are a student, hobbyist, or engineer, this project offers a practical introduction to biomedical instrumentation and embedded systems.

Understanding the Basic Components

A reliable heart rate monitor relies on a few key electronic components. Each part plays a critical role in sensing, processing, and displaying the pulse rate. Below is an expanded list of components required for this project, along with recommendations for optimal performance.

  • PIC microcontroller (e.g., PIC16F877A): This 40-pin microcontroller from Microchip offers an integrated analog-to-digital converter (ADC), multiple I/O ports, and timers. Its low power consumption and wide availability make it ideal for DIY medical devices. For a more compact design, consider the PIC18F series with built-in comparators.
  • Infrared (IR) LED and photodiode or phototransistor: An IR LED with a wavelength around 940 nm pairs well with a photodiode designed for the same range (e.g., TSOP1738 or BPW96C). The photodiode detects reflected light changes caused by blood flow variations. Using a matched pair improves signal stability.
  • Resistors and capacitors: Resistors (e.g., 220Ω for LED current limiting, 10kΩ for pull-ups) and capacitors (e.g., 0.1µF for decoupling, 10µF for filtering) are essential for biasing and smoothing the sensor signal. A low-pass filter with a cutoff frequency around 2-3 Hz helps isolate the heart rate component.
  • LCD display (16x2 character) or LEDs: A standard HD44780-compatible LCD provides a clear numerical readout of beats per minute (BPM). For minimalist designs, a row of LEDs can indicate pulse rhythm. Alternatively, use an OLED display for better visibility.
  • Power supply (5V battery or DC adapter): A stable 5V source is required for the PIC and peripherals. A 9V battery with a 7805 regulator works well for portable use. Avoid noisy supplies to prevent ADC errors.
  • Connecting wires and breadboard: Use a solderless breadboard for prototyping; jumper wires enable easy reconfiguration. For permanent builds, stripboard or PCB is recommended.

Additional optional components include an op-amp (e.g., LM358) for signal amplification, a potentiometer for LCD contrast adjustment, and a buzzer for audible pulse feedback.

Working Principle

The heart rate monitor operates on the principle of photoplethysmography (PPG), a non-invasive optical technique that measures blood volume changes in microvascular tissue. When the heart contracts, blood surges through arteries and capillaries, altering the amount of light absorbed or reflected by the tissue. By illuminating the skin with an infrared light source and detecting the reflected intensity, the device captures a waveform corresponding to each heartbeat.

The IR LED shines light into the fingertip or earlobe. The photodiode, positioned adjacent or opposite to the LED, converts the reflected light into a current. As blood volume fluctuates with each cardiac cycle, the reflected light intensity varies—slightly more absorption during systole (heart contraction) and less during diastole (relaxation). This creates an analog signal that oscillates in sync with the pulse.

Signal Processing

The analog signal from the photodiode is first conditioned through a simple resistor-capacitor (RC) low-pass filter to remove high-frequency noise (e.g., from ambient light or motion). The filtered signal is then fed into one of the PIC’s ADC channels. The PIC16F877A has a 10-bit ADC that converts the voltage into a digital value ranging from 0 to 1023.

The microcontroller firmware performs several processing steps:

  • Sampling: The ADC is read at a fixed rate, typically 100–200 samples per second, to capture the pulse waveform accurately.
  • Filtering: A software low-pass filter (e.g., moving average or exponential smoothing) removes residual noise. Optionally, a high-pass filter eliminates baseline drift caused by movement.
  • Peak detection: The algorithm identifies systolic peaks by comparing each sample to a dynamic threshold. A common method is to detect when the signal rises above a threshold and then falls below it, indicating a heartbeat. Time stamps are recorded at each peak.
  • BPM calculation: The interval between consecutive peaks (i.e., the beat-to-beat interval) is measured using the PIC’s timer module. BPM is computed as 60 ÷ interval (in seconds). For accuracy, the device averages the last 4–8 intervals to smooth variations.

This signal chain, though simple when implemented on a PIC, demonstrates core concepts in medical device design: sensing, conditioning, digitization, and algorithmic analysis.

Building the Circuit

Assembling the circuit requires careful placement of components to minimize noise and ensure stable readings. Begin by setting up the IR LED and photodiode on the breadboard. Place the IR LED on one side of the tissue (e.g., fingertip) and the photodiode on the other, or use a reflectance configuration where both are on the same side—the latter is more compact but requires shielding from ambient light.

Connect the photodiode in a voltage divider configuration: one terminal to +5V through a 10kΩ resistor, the other to ground directly. The junction between the photodiode and resistor serves as the analog output, which connects to the PIC’s ADC pin (e.g., RA0/AN0 on the PIC16F877A). Add a 0.1µF capacitor from this node to ground to form a low-pass filter with the resistor.

For the IR LED, connect its anode through a 220Ω current-limiting resistor to +5V, and its cathode to ground. Ensure the LED and photodiode are optically coupled—cover them with a dark tube or enclosure to block external light interference.

Connect the LCD module to Port B of the PIC using a 4-bit data bus (pins RB4–RB7) and control lines (RS, E, and optionally RW) on other ports. Include a 10kΩ potentiometer between Vdd and Vss of the LCD for contrast adjustment. Also, connect a 10kΩ pull-up resistor on the MCLR pin to avoid spurious resets.

Power the circuit with a regulated 5V supply. Decouple the Vdd and Vss pins of the PIC with a 10µF capacitor in parallel with a 0.1µF capacitor. Double-check all connections before applying power to prevent damage.

Programming the PIC

Firmware development for the PIC microcontroller is carried out in an integrated development environment (IDE) such as MPLAB X, using either assembly or C (e.g., with XC8 compiler). The program must manage ADC operations, timer interrupts, peak detection logic, and display updates. Below is an outline of the firmware structure.

Firmware Structure

Initialization: Configure the oscillator (e.g., 4 MHz internal or external), set the ADC module with a reference voltage of 5V and a sample time of 10–20 µs, enable timer1 for interval measurement, and initialize the LCD driver for 4-bit mode.

Main Loop: The endless loop performs the following tasks:

  1. Read the ADC channel (e.g., channel 0) after a fixed delay (e.g., 5 ms). Store the sample in a buffer.
  2. Apply a software filter: a moving average of the last 10 samples reduces noise without significant signal delay.
  3. Run a peak detection algorithm: compare the current filtered value to a threshold that is dynamically set to 60% of the peak-to-peak amplitude. If the value exceeds the threshold and the previous value was below, a peak is declared.
  4. On detecting a peak, capture timer1 count and compute the interval since the last peak. If the interval is valid (e.g., between 300 ms and 2000 ms, corresponding to 30–200 BPM), calculate BPM = 60000 / interval (in ms).
  5. Update a running average of BPM over the last 4 intervals and display the result on the LCD.
  6. Clear the display before each update to avoid text ghosting.

Example C code snippet (simplified):

unsigned int read_adc() {
    ADCON0bits.GO = 1;
    while (ADCON0bits.GO);
    return (ADRESH << 8) + ADRESL;
}
// In main loop:
raw = read_adc();
filtered = (raw + last_filtered * 3) / 4; // exponential smoothing
// Peak detection and BPM logic follows

The firmware should also include debounce logic to prevent false peaks from noise, such as requiring a minimum refractory period (e.g., 200 ms) between detections.

For beginners, Microchip provides libraries and app notes that simplify development. MPLAB X IDE is free and supports all PIC families.

Calibration and Testing

Once the circuit and firmware are ready, calibration ensures accurate heart rate readings. Begin by verifying the photodiode output voltage changes when you place a finger between the IR LED and sensor. Use a multimeter on the ADC pin to observe fluctuations—a healthy pulse should produce a ripple of 100–500 mV amplitude.

To calibrate the BPM calculation, compare the device output with a commercial heart rate monitor or a smartphone PPG app. Adjust the moving average window and threshold percentage to match. Typical adjustments include lowering the threshold if the device misses beats, or raising it if it counts noise as beats.

Test under controlled conditions: sit still with the hand at heart level, avoid motion, and ensure the finger is clean and dry. Test on multiple individuals to verify consistency. The device should display a stable BPM within 2–3 beats of a reference monitor. If the reading is erratic, check for ambient light leaks, improve circuit shielding, or increase the filter’s time constant.

Applications and Extensions

This low-cost heart rate monitor has numerous practical uses:

  • Educational projects: It introduces students to biomedical sensors, signal processing, and embedded systems in a tangible way.
  • Personal fitness tracking: Combined with a data logger, the device can monitor resting heart rate or during exercise (though motion artifacts require more advanced filtering).
  • Remote health monitoring: Adding a Bluetooth module (e.g., HC-05) allows transmitting BPM data to a smartphone or computer for long-term tracking.

Extensions to the basic design include:

  • Wireless connectivity: Integrate a Bluetooth module to send data serially.
  • Data logging: Use an external EEPROM (e.g., 24LC256) to store hourly readings.
  • Multi-sensor system: Add a temperature sensor (e.g., LM35) to monitor body temperature alongside heart rate.
  • Graphical display: Upgrade to a graphical LCD or OLED to plot the PPG waveform in real time.
  • Motion artifact rejection: Implement adaptive filtering using an accelerometer to subtract motion noise.

These expansions align with principles of mHealth (mobile health) and promote self-monitoring in low-resource settings.

Advantages and Considerations

Building a heart rate monitor with a PIC microcontroller offers several advantages:

  • Low cost: Total component cost is under $20, making it accessible for classrooms and hobbyists.
  • Educational value: Developers gain hands-on experience with ADC, timers, and digital filtering.
  • Customizability: The firmware can be modified for different sensor types or processing algorithms.
  • Open-source potential: Design files and code can be shared and improved by the community.

However, consider the limitations. The device is not medical-grade and should not replace professional diagnostic equipment. Motion artifacts and ambient light can cause errors, though careful design mitigates these issues. For higher accuracy, consider using a dedicated bio-sensing IC like the AD8232 for ECG monitoring, which requires different signal conditioning.

Conclusion

Creating a low-cost heart rate monitor with a PIC microcontroller is a rewarding project that bridges electronics, programming, and physiology. With basic components and a clear understanding of photoplethysmography and signal processing, you can assemble a functional device that provides real-time pulse data. This project not only demonstrates the power of accessible hardware but also inspires innovation in personal health monitoring. By expanding on this foundation—adding wireless features, data storage, or advanced filtering—you can tailor the system to educational, fitness, or research applications, fostering a deeper knowledge of biomedical engineering.