Air Mattress Controller V1
Open-Source Adjustable Firmness System

4.0 4. Control System

Stored Targets

Each zone stores:

  • occupied pressure (user-defined comfort setting)
  • empty-bed pressure (preload pressure)

These values are updated only when the user changes firmness.

Why occupancy detection is required

The controller must determine which state the system is in:

  • empty state (no external load)
  • occupied state (normal user load)
  • transitional state (user entering, leaving, or moving)

This classification is based on:

  • pressure magnitude
  • rate of pressure change

This state determination is used to decide:

  • which pressure target should be maintained
  • whether a pressure change should be ignored or acted on

Without this classification, the system cannot distinguish load-induced pressure changes from true pressure changes caused by air movement.

As a result:

  • pressure decreases caused by a user leaving the bed may be misclassified as leaks and trigger unintended inflation
  • pressure increases caused by a user lying down may be misclassified as overpressure and trigger unintended venting

When properly calibrated, the system maintains an empty-bed pressure that results in the correct comfort level immediately upon occupancy.

Transient Detection

Transient detection identifies short-duration pressure changes that do not represent a stable system condition.

Examples include:

  • a user getting on or off the bed
  • body movement or repositioning
  • pressure disturbances introduced when valves open or close

The controller evaluates:

  • rate of pressure change (dP/dt)
  • duration of the change

Classification logic:

  • pressure changes that occur rapidly and resolve quickly are treated as transient events and are ignored
  • pressure changes that persist over a longer duration are treated as valid system conditions and may trigger control actions

This prevents:

  • reacting to normal movement
  • unnecessary valve actuation
  • oscillation caused by overcorrection

Transient thresholds must be tuned based on observed system behavior.

Predictive Control and Auto-Tuning

During fill and vent operations, pressure continues to change briefly after a valve is closed due to airflow inertia and system compliance.

The controller:

  • monitors the rate of pressure change (dP/dt)
  • estimates how much pressure will continue changing after the valve closes
  • adjusts valve timing to avoid under- or overshooting the target pressure

Auto-tuning behavior

The system improves over time by observing real system response. It records:

  • rate of pressure change during fill and vent operations
  • amount of overshoot or undershoot after valve closure

Using this information, the controller:

  • refines valve timing
  • improves prediction accuracy
  • adapts to differences in mattress size, material, and leak characteristics

Operating States

Empty State

  • maintains empty-bed pressure
  • samples pressure every 60 seconds
  • slow sampling reduces unnecessary system activity

Occupied State

  • maintains user-defined comfort setting
  • samples every 2–5 seconds

Adjustment State

  • active during pressure changes
  • samples at 5–10 Hz
  • applies predictive control
  • updates stored targets after stabilization

Multi-Occupant Logic (stationary mode only)

Why it is needed

In real-world use, the load on the mattress can change after the initial comfort setting is established.

Examples include:

  • a second person getting into bed
  • a child or pet joining
  • one person leaving while another remains

These events create sustained pressure changes that are not caused by air being added or removed.

What it does

The system detects sustained pressure deviation from expected occupied pressure.

When detected, the controller adjusts pressure toward the user-defined comfort setting.

This prevents:

  • sustained pressure offset from the original setting
  • incorrect firmness after load changes

Adjustable Base Mode

When the bed frame is articulated, the mattress geometry changes.

This causes:

  • a reduction in internal volume
  • an increase in measured pressure

This pressure increase is caused by mechanical deformation, not added air.

Why special handling is required

Without this mode, the system would interpret the pressure increase as overpressure and vent air.

This would cause:

  • incorrect firmness while articulated
  • incorrect pressure when returning flat

Behavior

  • multi-occupant logic is disabled
  • articulation-induced pressure changes are ignored
  • pressure is maintained relative to the current shape

Tradeoff: multi-occupant detection is not reliable in this mode.

DIY Air Mattress Controller V1 • Open Source Project