Skip to content

jason-n-tran/digital-spirometer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Digital Spirometer

Arduino C++


Overview

A portable, Arduino-based digital spirometer for measuring respiratory volumes and lung capacity. This device provides real-time breath analysis with an intuitive OLED interface, enabling clinical respiratory assessments through multi-mode measurement capabilities including forced vital capacity (FVC) analysis.


Table of Contents


About The Project

Motivation

Traditional spirometers are expensive and often inaccessible in low-resource settings. This project democratizes respiratory health monitoring by providing an open-source, cost-effective alternative using readily available Arduino components. It enables accurate measurement of lung capacity metrics essential for diagnosing respiratory conditions, monitoring asthma, and tracking post-operative recovery.

Key Features

  • Multi-Mode Respiratory Measurement

    • Exhalation mode for FEV₁ and peak flow measurements
    • Inhalation mode for inspiratory volume assessment
    • FVC protocol with automated multi-breath sequencing (IC, TV, ERV assessment)
  • Real-Time OLED Display Interface

    • 128×64 pixel SSD1306 OLED screen with dynamic menu navigation
    • Live breath status feedback and volume results
    • Scrolling text animation for branding display
  • Calibration System

    • Automated pressure-to-volume conversion calibration using 3L reference standard
    • Separate calibration factors for inhalation and exhalation modes
    • Configurable conversion ratios (EX_VOLT_TO_L_RATIO, IN_VOLT_TO_L_RATIO)
  • Multi-Button Navigation

    • Intuitive up/down/confirm button interface for mode selection
    • Digital input handling with debounce capability
    • Menu-driven user experience for clinical ease-of-use
  • Dual Pressure Sensor Support

    • Analog sensor input sampling at configurable 10ms intervals
    • Baseline voltage calibration during initialization
    • Threshold-based breath detection (±0.05V sensitivity)
  • Advanced Respiratory Metrics

    • FVC (Forced Vital Capacity) calculation
    • TV (Tidal Volume) averaging
    • IRV (Inspiratory Reserve Volume) derivation
    • ERV (Expiratory Reserve Volume) derivation

Built With

  • Arduino IDE — Embedded development environment
  • Adafruit SSD1306 — OLED display driver library
  • Adafruit GFX — Graphics library for display rendering
  • Wire/I2C — I2C communication protocol for OLED
  • C++ — Embedded systems programming language

Getting Started

Prerequisites

Hardware:

  • Arduino microcontroller (tested with Arduino Mega/Uno compatible board)
  • SSD1306 128×64 OLED display module (I2C interface)
  • Analog pressure/flow sensor (e.g., MPXV5004DP or equivalent)
  • 3 digital input buttons (push-to-ground convention)
  • 5V power supply
  • I2C pull-up resistors (typically 4.7kΩ)

Software:

  • Arduino IDE 1.8.x or later
  • USB cable for board programming

Installation

  1. Clone or download the repository:

    git clone https://github.com/jason-n-tran/digital-spirometer.git
    cd digital-spirometer
  2. Install required Arduino libraries:

    • Open Arduino IDE → Sketch → Include Library → Manage Libraries
    • Search for and install:
      • Adafruit SSD1306 (by Adafruit Industries)
      • Adafruit GFX Library (by Adafruit Industries)
    • Alternatively, use the Library Manager UI (Tools → Manage Libraries)
  3. Connect hardware:

    • OLED Display (I2C):
      • SDA → Arduino SDA (A4 on Uno, 20 on Mega)
      • SCL → Arduino SCL (A5 on Uno, 21 on Mega)
      • VCC → 5V
      • GND → GND
    • Pressure Sensor:
      • Analog output → A0
      • GND → GND
      • VCC → 5V
    • Buttons:
      • Up button → Pin 4
      • Confirm button → Pin 5
      • Down button → Pin 6
      • All buttons should connect to GND when pressed
  4. Upload firmware:

    • Select your board type (Tools → Board)
    • Select correct COM port (Tools → Port)
    • Open digital-spirometer.ino and click Upload

Usage

Calibration

Before clinical use, calibrate the sensor with a known 3L reference volume:

  1. Open calibration.ino in Arduino IDE
  2. Upload to your Arduino board
  3. Open Serial Monitor (115200 baud)
  4. When prompted: "Pump 3L when prompted"
  5. Provide exactly 3L of air into the device using a calibration syringe or bellows
  6. The device will output the calibration factor
  7. Update the constants in digital-spirometer.ino:
    #define EX_VOLT_TO_L_RATIO 2.94  // Your exhalation calibration factor
    #define IN_VOLT_TO_L_RATIO 2.57  // Your inhalation calibration factor

Operation

  1. Power on the device — Welcome message displays on OLED
  2. Select measurement mode:
    • Use Up/Down buttons to navigate: Exhalation, Inhalation, or FVC
    • Press Confirm button to select
  3. Perform measurement:
    • Follow on-screen instructions
    • Breathe steadily into the device mouthpiece
    • Device automatically detects breath completion
    • Results display with calculated volume in liters
  4. Return to menu: Device automatically returns to mode selection after 2 seconds

Configuration

Sampling Parameters (in digital-spirometer.ino):

#define DELTA_T 0.01        // Sampling interval in seconds (10ms)
#define DELAY 100           // Button debounce delay in milliseconds
#define PRESSURE_INPUT 14   // Unused (for future expansion)

Calibration Factors:

#define EX_VOLT_TO_L_RATIO 2.94  // Exhalation voltage-to-volume conversion
#define IN_VOLT_TO_L_RATIO 2.57  // Inhalation voltage-to-volume conversion

Button Pins:

#define up_button 4         // GPIO pin for up navigation
#define down_button 6       // GPIO pin for down navigation
#define confirm_button 5    // GPIO pin for confirm/select

Breath Detection Threshold:

while(V_val >= V_amb + 0.05 && ...)  // Breath detection sensitivity (±0.05V)

Roadmap

  • Real-time exhalation and inhalation measurement modes
  • FVC protocol with multi-breath respiratory volume assessment
  • OLED display with button-driven menu navigation
  • Data Logging — SD card module integration for session storage and export
  • Bluetooth Connectivity — Wireless data transmission to mobile/desktop applications
  • Unit Testing — Comprehensive sensor calibration and accuracy validation suite
  • Web Dashboard — Online portal for historical trend analysis and clinical reports
  • Battery Management — Low-power sleep modes and battery status indication
  • Multi-Language Support — Internationalization for global clinical deployment

Contact & Support

Developer: Jason Tran

📧 Email: tran219jn@gmail.com

🌐 Website: jasontran.pages.dev