# Stop a test when a reading goes out of range

# Stop a test when a reading goes out of range

Give a channel a shutdown limit. The test stops on its own the moment a
reading crosses it.

## Before you start

- A Trellis setup open in Phloem Computer. See [Trellis](https://phloem.ai/docs/trellis/).
- The channel you want to watch shows on **Live**.
- Every output the setup commands has a `safe=` value.

## Steps

1. Open **Trellis** in the rail, open your setup, and switch to **Code**.
2. On the channel's `ch.read(...)` line, add `limits=` with the bounds. Add
   `checks=True` to arm them:

   ```python
   setup("heater")

   ch = channels()
   ch.read("/demo/temperature", unit="degC", range={"min": 0, "max": 100},
           limits=limits(hi=70, hihi=80), checks=True)
   ch.write("/demo/heater_on", dtype="bool", safe=False)

   page("Heater test", layout=col(row(gauge(ch["/demo/temperature"]), alarms())))
   ```

   | Bound | Does |
   |---|---|
   | `hihi` | stops the test at or above this value |
   | `lolo` | stops the test at or below this value |
   | `hi` / `lo` | warns past this value; the test keeps running |

3. Press **Deploy**. The status chip reads **running** once the channel
   reports.

## Check it worked

When the reading reaches `hihi`:

- The status chip turns **tripped**.
- An **Interlock tripped** card reads *Outputs held at safe values.* It names
  the bound that fired, such as `/demo/temperature hihi`.
- Every output goes to its `safe=` value.

The test stays stopped. Once the reading is back in range, press **Reset** to
re-arm. Until then, **Reset** is disabled.

> **Note:** Without `checks=True`, `limits=` only colours gauges and charts.
> Nothing stops. To drive only *some* outputs, use an
> [interlock](https://phloem.ai/docs/trellis/interlocks/).

- [Stop conditions](https://phloem.ai/docs/trellis/checks/): The stop-condition reference
- [Interlocks](https://phloem.ai/docs/trellis/interlocks/): Drive chosen outputs safe on a condition
- [Get a Slack message](https://phloem.ai/docs/guides/alert-in-slack/): Tell someone without stopping the test
