Skip to content

anandteertha/Lung-Capacity-Checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lung Capacity Checker

A hardware and software system for measuring lung volumes and capacity using pressure sensing and optional water-displacement methods. Designed to work with NodeMCU/ESP8266 and a mobile or web app for data display and basic pulmonary assessment.

Overview

The project measures respiratory volumes (Tidal Volume, IRV, ERV, Vital Capacity, etc.) by:

  1. Pressure-based method — A BMP180 pressure sensor in a sealed container with a small opening. Air from breathing changes the pressure; data is streamed over WiFi to a server or app.
  2. Water-displacement method — Blowing into a closed water-filled container; two pressure sensors (top and bottom) are used to compute water-level change and infer exhaled volume.

The Arduino/NodeMCU firmware reads the sensor, connects to WiFi, and streams pressure data over TCP to the Android app (DeepBlue22). The app guides users through each test type, computes volumes from pressure, and can generate a report with optional TensorFlow Lite–based inference.

Lung Volumes Measured

Volume Description Typical adult range
TV (Tidal Volume) Air per normal breath ~300–500 mL
IRV (Inspiratory Reserve) Extra air after normal inhale ~1900–3300 mL
ERV (Expiratory Reserve) Extra air after normal exhale ~700–1200 mL
VC (Vital Capacity) Max exhale after max inhale (TV + IRV + ERV) ~4800 mL
RV (Residual Volume) Air left after max exhale ~1200 mL (indirect)
TLC (Total Lung Capacity) VC + RV ~4–6 L

Definitions and formulas are documented in pressure to volume/p2v.py and formulas.txt.

Hardware

  • NodeMCU (ESP8266) or Arduino + ESP8266 Wi‑Fi module
  • BMP180 pressure sensor (I2C: SDA → D2, SCL → D1 on NodeMCU; VCC 3.3V, GND)
  • Jumper wires, breadboard (or PCB)
  • Power: battery or USB
  • Container: sealed plastic container; for water method, a second container and straw/opening for blowing

Approximate component notes and costs are in components.txt and cost-of-components.txt. Wiring summary in arduino files/pressure_sensor/details.txt and wires.txt.

Project Structure

Lung-Capacity-Checker/
├── README.md
├── first-app-details.txt      # App UX design: login, test selection, demos, flow
├── formulas.txt               # Pressure/flow/volume math (e.g. Bernoulli-style)
├── components.txt             # Hardware list
├── wires.txt                  # Jumper counts
├── cost-of-components.txt     # Rough component costs
├── inhale+exhale.txt         # Pressure-sensor method overview
├── exhale-using-closed-container-waterLevel.txt   # Water-displacement method
├── LUNG PULMONARY DISORDERS.txt   # FEV1/FVC ratio (obstructive vs restrictive)
├── pressure to volume/
│   └── p2v.py                # Lung volume definitions (VC, TV, IRV, ERV, FRC, RV, TLC)
├── Android App/               # Android app (DeepBlue22) — see “Android App” below
│   ├── app/
│   │   ├── src/main/java/com/example/deepblue22/   # Activities, SocketHelper, VolumeCalculation
│   │   ├── src/main/res/                           # Layouts, drawables, values
│   │   └── src/main/ml/                            # TensorFlow Lite model (optional)
│   ├── app/build.gradle
│   └── build.gradle
└── arduino files/
    ├── socket_with_app/      # BMP180 + TCP server on port 8080 — use this with the app
    ├── pressure_sensor/      # BMP180 read (pressure, temperature, altitude)
    ├── nodemcuServernew/     # ESP8266 web server (HTTP)
    ├── PostHttpClient/       # POST JSON to a server
    ├── node_mcu_as_server/   # NodeMCU as server
    ├── wifiManger_node_mcu/  # WiFi manager
    └── ...                   # Other sketches (blink, UDP, I2C, etc.)

Arduino / Firmware

  • Use with the Android app: arduino files/socket_with_app/socket_with_app.ino — BMP180 on I2C (SDA=14, SCL=12), WiFi connection, and a TCP server on port 8080. The app connects to the NodeMCU’s IP on this port to receive pressure data. Set ssid and password in the sketch, then flash; the app auto-discovers the device on the same WiFi.
  • Pressure sensor only: arduino files/pressure_sensor/pressure_sensor.ino — BMP180 on I2C, reports pressure (hPa), temperature, and optional sea-level/altitude.
  • WiFi server (HTTP): arduino files/nodemcuServernew/nodemcuServernew.ino — HTTP routes like /, /stream/start, /stream/stop. Configure STASSID and STAPSK.
  • HTTP client: arduino files/PostHttpClient/PostHttpClient.ino — POSTs JSON to a configurable server (SERVER_IP).

Set your WiFi credentials (and server IP where needed) in the sketches before flashing.

Pressure to Volume

  • pressure to volume/p2v.py — Documents lung volume definitions and relationships (VC, TV, IRV, ERV, FRC, RV, TLC).
  • formulas.txt — Reference formulas (flow/velocity from pressure difference and cross-sectional areas).
  • In the app: VolumeCalculation (Java) implements pressure-to-volume using tube diameters, atmospheric pressure, and temperature-dependent air density and viscosity, aligned with the physics in formulas.txt.

Basic Pulmonary Interpretation

LUNG PULMONARY DISORDERS.txt describes using the ratio:

  • FEV1 / FVC × 100
    • ≈ 80% — Normal
    • < 80% — Obstructive pattern
    • > 80% — Restrictive pattern

This requires time-resolved flow/volume (e.g. FEV1 and FVC); the current hardware provides a basis for volume estimation from pressure over time.

Android App (DeepBlue22)

The app (Android App/) runs on Android (min SDK 21, target 31), uses Java, and connects to the NodeMCU over TCP on port 8080 (see SocketHelper and arduino files/socket_with_app/).

Setup and flow

  1. MainActivity — User enters name, age, and gender. The app scans the local network to find the NodeMCU (same WiFi required) and stores its IP.
  2. Two modes:
    • Manual — Start with Tidal Volume → then Timer1 → Inspiratory Capacity (Timer2) → Expiratory Capacity (Timer3) → PercentageDisorder (FEV1/FVC ratio) → ReportActivity.
    • Automatic — AutomaticActivity (setup) → TidalVolumeAutomatic → ICAutomatic → ECAutomatic → DisorderAutomatic → ReportActivity.
  3. Measurement — For each test, the app opens a socket to the device, sends "end" when the user stops; the device responds with pressure (and optionally time) data. VolumeCalculation converts pressure to volume (mL).
  4. Report — ReportActivity shows TV, IC, IRV, EC, ERV, VC, TLC, disorder classification, and ratio. It can generate a PDF report and uses an optional TensorFlow Lite model (app/src/main/ml/nice_to_have.tflite) for inference.

Build and run

  • Open Android App/ in Android Studio (or use Gradle from the project root).
  • Build and run on a device or emulator. Ensure the phone and NodeMCU are on the same WiFi; flash socket_with_app.ino with your network credentials so the app can discover and connect to the board.

Key classes

Class Role
MainActivity Name, age, gender; NodeMCU discovery; launch Manual or Automatic flow
SocketHelper TCP client to NodeMCU on port 8080
VolumeCalculation Pressure → volume (diameters, air density, viscosity)
TidalVolume, InspiratoryCapacity, ExpiratoryCapacity Manual test screens
TidalVolumeAutomatic, ICAutomatic, ECAutomatic, DisorderAutomatic Automatic flow
ReportActivity Results, disorder/ratio, PDF export, optional TFLite

Original UX ideas (login/register, demos, etc.) are in first-app-details.txt.

Disclaimer

This project is for educational and prototyping purposes. It is not a medical device. Do not use it for clinical diagnosis or treatment. For any health concerns, use equipment approved for medical use and consult a healthcare provider.

License

See repository for license information.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors