commit 81849f16b8fc3fd00ffcdf50111a5d68b843a7e3 Author: Jeff Emmett Date: Fri Dec 26 10:20:33 2025 -0500 Initial commit: project plan for breath-synchronized fan system Biofeedback system that detects breathing via sensors and synchronizes PC tower fans to inflate a bag during inhalation phases. πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 diff --git a/PROJECT_PLAN.md b/PROJECT_PLAN.md new file mode 100644 index 0000000..6457e58 --- /dev/null +++ b/PROJECT_PLAN.md @@ -0,0 +1,260 @@ +# Breath-Synchronized Fan & Bag Inflation System + +## Project Overview + +A biofeedback system that detects a user's breathing pattern via sensors and synchronizes computer tower fans to inflate a bag during inhalation phases. + +--- + +## System Architecture + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Breath Sensor │────▢│ Microcontroller │────▢│ Fan Controller β”‚ +β”‚ (on chest/nose)β”‚ β”‚ (Arduino/ESP32) β”‚ β”‚ (PWM/MOSFET) β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ + β–Ό + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ PC Tower Fans β”‚ + β”‚ (12V, 3-4 pin) β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ + β–Ό + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ Inflation Bag β”‚ + β”‚ (sealed inlet) β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +--- + +## Component Options + +### 1. Breath Sensors (Choose One) + +| Sensor Type | Pros | Cons | Est. Cost | +|-------------|------|------|-----------| +| **Chest Strap Stretch Sensor** | Non-invasive, comfortable | Requires calibration per user | $15-30 | +| **Nasal Airflow Thermistor** | Very accurate, medical-grade | Intrusive, needs cleaning | $5-15 | +| **Piezoelectric Belt** | Simple, reliable | Can slip, position-sensitive | $10-20 | +| **BioImpedance (AD8232)** | Multi-signal (breath + heart) | Complex setup, needs electrodes | $10-25 | +| **Microphone/Sound Sensor** | No contact required | Ambient noise interference | $5-10 | +| **Pressure Sensor (BMP280)** | Very sensitive | Needs sealed enclosure | $5-10 | + +**Recommendation:** Chest strap with conductive rubber stretch sensor or piezoelectric element - balances accuracy with comfort for seated use. + +### 2. Microcontroller + +| Option | Pros | Cons | Est. Cost | +|--------|------|------|-----------| +| **Arduino Nano** | Simple, lots of tutorials | Limited processing | $5-15 | +| **ESP32** | WiFi/BLE, dual-core, more pins | Overkill for basic version | $8-15 | +| **Raspberry Pi Pico** | Powerful, cheap, PIO for precise timing | Less community support | $4-8 | + +**Recommendation:** Arduino Nano for simplicity, ESP32 if you want wireless monitoring/control later. + +### 3. Fan Control + +| Method | Description | Components Needed | +|--------|-------------|-------------------| +| **PWM via MOSFET** | Speed control 0-100% | IRLZ44N MOSFET, flyback diode | +| **Relay (On/Off)** | Simple binary control | 5V relay module | +| **Fan Controller IC** | Dedicated chip | EMC2301 or similar | + +**Recommendation:** PWM via MOSFET - allows smooth ramping that mirrors breath intensity. + +### 4. Fans + +- Standard 120mm PC tower fans (12V, 0.2-0.5A each) +- 4-pin PWM fans allow direct speed control +- 3-pin fans need external PWM circuit +- Consider 2-4 fans for adequate airflow + +### 5. Inflation Bag + +- Medical ventilator bags (Ambu-style) - designed for this +- Weather balloon material with one-way valve +- Custom sewn ripstop nylon with inlet fitting +- Volume: 2-5 liters typical for breath visualization + +--- + +## Bill of Materials (Estimated) + +| Component | Quantity | Est. Cost | +|-----------|----------|-----------| +| Stretch sensor (chest strap) | 1 | $20 | +| Arduino Nano | 1 | $10 | +| IRLZ44N MOSFET | 2-4 | $5 | +| 1N4007 Diodes (flyback) | 2-4 | $2 | +| 120mm PC Fans | 2-4 | $20-40 | +| 12V 2A Power Supply | 1 | $10 | +| Breadboard + Jumpers | 1 set | $10 | +| Inflation bag + fitting | 1 | $15-30 | +| Enclosure/mounting | - | $10-20 | +| **Total** | | **$100-150** | + +--- + +## Software Architecture + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Main Loop β”‚ +β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ +β”‚ β”‚ +β”‚ 1. READ sensor value (analog 0-1023) β”‚ +β”‚ β”‚ β”‚ +β”‚ β–Ό β”‚ +β”‚ 2. FILTER noise (moving average, 5-10 samples) β”‚ +β”‚ β”‚ β”‚ +β”‚ β–Ό β”‚ +β”‚ 3. DETECT breath phase β”‚ +β”‚ β”œβ”€β”€ Rising signal = INHALE β”‚ +β”‚ β”œβ”€β”€ Falling signal = EXHALE β”‚ +β”‚ └── Stable = PAUSE β”‚ +β”‚ β”‚ β”‚ +β”‚ β–Ό β”‚ +β”‚ 4. MAP breath intensity to fan speed (0-255 PWM) β”‚ +β”‚ β”‚ β”‚ +β”‚ β–Ό β”‚ +β”‚ 5. RAMP fan speed (smooth transitions) β”‚ +β”‚ β”‚ β”‚ +β”‚ β–Ό β”‚ +β”‚ 6. OUTPUT PWM to MOSFET gate β”‚ +β”‚ β”‚ +β”‚ Loop rate: 50-100 Hz β”‚ +β”‚ β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +### Key Algorithm: Breath Detection + +```cpp +// Pseudocode +float baseline = calibrate(); // 5-second calm breathing average +float threshold = baseline * 0.1; // 10% deviation triggers + +void loop() { + float current = readSensor(); + float filtered = movingAverage(current, 10); + + if (filtered > baseline + threshold) { + // INHALING - ramp fans up proportionally + int intensity = map(filtered, baseline, maxInhale, 0, 255); + setFanSpeed(intensity); + } else { + // EXHALING or PAUSE - fans off, bag deflates passively + setFanSpeed(0); + } + + // Adaptive baseline (slow drift compensation) + baseline = baseline * 0.999 + filtered * 0.001; +} +``` + +--- + +## Wiring Diagram + +``` + +12V (Fan Power) + β”‚ + β”‚ + Arduino Nano β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β” + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ + β”‚ D9 │───────┬──────────▢│G FAN β”‚ + β”‚ (PWM) β”‚ β”‚ β”‚ 120mm β”‚ + β”‚ β”‚ β”Œβ”€β”€β”΄β”€β”€β” β”‚ β”‚ + β”‚ GND │─────IRLZ β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ + β”‚ β”‚ β”‚44N β”‚ β”‚ + β”‚ A0 │◀──── β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ (Sensor) β”‚ β””β”€β”€β”¬β”€β”€β”˜ GND + β”‚ β”‚ β”‚ + β”‚ 5V │───────┼──────▢ Sensor VCC + β”‚ GND │───────┼──────▢ Sensor GND + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ + β”‚ + β”Œβ”€β”€β”΄β”€β”€β” + β”‚1N4007β”‚ (Flyback diode) + β””β”€β”€β”¬β”€β”€β”˜ + β”‚ + GND +``` + +--- + +## Implementation Phases + +### Phase 1: Sensor Validation +- [ ] Select and acquire breath sensor +- [ ] Wire sensor to Arduino +- [ ] Write basic serial plotter sketch +- [ ] Verify clean breath signal on serial plotter +- [ ] Tune filtering parameters + +### Phase 2: Fan Control +- [ ] Wire MOSFET circuit on breadboard +- [ ] Test PWM control with potentiometer +- [ ] Verify fan speed varies 0-100% +- [ ] Add flyback diode protection +- [ ] Test with multiple fans if needed + +### Phase 3: Integration +- [ ] Combine sensor input with fan output +- [ ] Implement breath detection algorithm +- [ ] Add calibration routine (button-triggered) +- [ ] Tune response curve (linear vs. exponential) +- [ ] Test full loop with user breathing + +### Phase 4: Bag System +- [ ] Design or acquire inflation bag +- [ ] Create sealed inlet with fan output +- [ ] Add one-way valve (prevents backflow on exhale) +- [ ] Test bag inflation matches breath cycle +- [ ] Adjust fan power for bag volume + +### Phase 5: Enclosure & Polish +- [ ] Design mounting for fans and bag +- [ ] Create comfortable sensor wearable +- [ ] Add status LEDs (power, breathing, calibrating) +- [ ] Optional: Add OLED display for breath rate +- [ ] Optional: Add WiFi for remote monitoring + +--- + +## Testing Checklist + +- [ ] Sensor responds to chest expansion (not just movement) +- [ ] No false triggers from ambient noise/vibration +- [ ] Fan ramps smoothly (no jerky motion) +- [ ] Bag inflates during inhale, deflates during exhale +- [ ] System works for different breathing rates (8-20 breaths/min) +- [ ] Calibration works for different users +- [ ] Safe shutdown if sensor disconnected +- [ ] No overheating after 30+ min operation + +--- + +## Safety Considerations + +1. **Electrical**: Use proper flyback diodes - fan motors create back-EMF +2. **Ventilation**: Ensure fans don't overheat in enclosure +3. **Bag Material**: Don't use latex (allergy risk) - use medical silicone or nylon +4. **Power**: Fuse the 12V supply line +5. **User Comfort**: Sensor shouldn't restrict breathing or movement + +--- + +## Optional Enhancements + +| Feature | Complexity | Description | +|---------|------------|-------------| +| Breath rate display | Low | Count peaks per minute, show on OLED | +| Guided breathing mode | Medium | LEDs/display guide user to target breath rate | +| Data logging | Medium | SD card or WiFi upload of session data | +| Multiple bags | Medium | Different bags for inhale vs exhale | +| Haptic feedback | Medium | Vibration motor mirrors breath | +| Sound sync | High | Audio tones follow breath pattern | +| VR integration | High | Breath controls virtual environment |