# Relay with Hysteresis (`hysteresis`)

> Switches its output to one level when the input rises above a threshold and back when it falls below a lower one.

![hysteresis](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/hysteresis.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/control/hysteresis/)

**Group:** Control · **Kind:** `{"block":"hysteresis","kind":"control"}`

## When to use it

Use it for a bang-bang (hysteresis) current controller, a thermostat, an under-voltage lockout or a Schmitt trigger. Use Comparator to compare two signals.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `in` | signal | Signal input |
| `out` | signal | yon or yoff |

## Common parameters

- `on`: Input above which the output switches to yon (Default: 0.5)
- `off`: Input below which the output switches to yoff; not above on (Default: -0.5)
- `yon`: Output after the input rises above on (Default: 1)
- `yoff`: Output after the input falls below off, and at the start (Default: 0)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `on` | — | 0.5 |  | Input above which the output switches to yon |
| `off` | — | -0.5 |  | Input below which the output switches to yoff; not above on |
| `yon` | — | 1 |  | Output after the input rises above on |
| `yoff` | — | 0 |  | Output after the input falls below off, and at the start |

_Parameter descriptions are in English in both languages._

## Model

The output is yon while the input is above on, yoff while it is below off, and keeps its last value in between, so the band from off to on is the hysteresis. It starts at yoff unless the input starts above on. on must not be below off; with on = off it is a comparator against that threshold. Code generation writes it with the held level in the state struct.

## Common mistakes

- The output changes only at a solver step, so the input can overshoot a threshold by up to one step's change. Keep maxStep small against how fast the input crosses the band.
- off above on is refused. A noisy input needs a band wider than its noise, or the output chatters at every crossing.

Problems rules: `compile.error`

## Datasheet and sources

There is no datasheet. For an under-voltage lockout, on and off are the rising and falling thresholds in the controller's data sheet.

## Example

Open the example with the command `file.openExample` and the name `demo:hysteresis`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
