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 <noreply@anthropic.com>
This commit is contained in:
commit
81849f16b8
|
|
@ -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 |
|
||||
Loading…
Reference in New Issue