# Pulse Detection

Trigger messages using external I/O pulse detection.

> [!CAUTION]
>
> **Tip:** There is a small recess inside the Soracom LTE-M Button for storing the accessory port cover so that you don't lose it.

The **Pulse Detection** external I/O mode allows you to connect your own circuit to the Soracom LTE-M Button using the 2-wire accessory in order to electronically trigger messages using external inputs.

In this mode, the button will detect when an external switch is pressed and released, and send a message similar to the message sent when clicking the built-in button.

> [!WARNING]
>
> If you want your circuit to trigger each time its opened or closed state changes, use the [Edge Detection](https://docs.soracom.io/en/devices/soracom-lte-m-button/io-modes/edge-detection) mode instead.

You can easily test this by connecting the included 2-wire accessory to the external I/O accessory port, then touching and releasing the two exposed wires, just as you would press and release the built-in button. You should see the LED start blinking green, indicating that the Soracom LTE-M Button has detected the external click and is now connecting to a cellular network.

As an example, you can connect a momentary switch that can be positioned separately from the Soracom LTE-M Button itself. Clicking the switch will send an [Event message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#event-message) or an [Alert message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#alert-message), with a detect type (Single short click, Double short click, or Single long click) corresponding to the length and number of clicks detected, just as if the built-in button was pressed.

![Example using Pulse Detection](https://docs.soracom.io/_astro/01-pulse-example.Dx9f93yn_Z1ar5b2.webp)

> [!NOTE]
>
> **Important!** The Soracom LTE-M Button provides its own voltage in order to detect whether the circuit is open or closed. **The 2-wire accessory must not be connected directly to an external power source.** Doing so may permanently damage the button.

There are many other types of sensors or circuits that can be used with Pulse Detection, such as a pressure pad to detect when someone steps on a particular area. You can also use a relay switch to connect other electronics, such as using an Arduino or Raspberry Pi with other sensors to trigger the relay.

## Behavior

When configured for **Pulse Detection**, the Soracom LTE-M Button will apply a small voltage to the external I/O. When it detects a change in voltage that indicates the circuit is closed due to an external switch being pressed, it will start a timer to measure the duration of the press. Once it detects another change in voltage that indicates the switch was released, it measures the timer and sends a message:

![Pulse detection timing diagram showing voltage changes](https://docs.soracom.io/_astro/02-pulse-behavior.CfhAqEnV_Z17OvC4.webp)

When the operation mode is configured as [Alert](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/alert) or [Alert + Heartbeat](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/alert-and-heartbeat), the button will send an [Alert message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#alert-message).

### Detect Types

The message sent by the button will indicate the type of change it detected:

- `Single short click` - Indicating that a single click less than 2 seconds in duration was detected
- `Double short click` - Indicating that two single clicks within 2 seconds were detected
- `Single long click` - Indicating that a single click longer than 2 seconds and shorter than 6 seconds in duration was detected

These detect types correspond to the same detect types of the built-in button.

> [!NOTE]
>
> Note that if the external switch is clicked for longer than 10 seconds, this will trigger a [Status message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#status-message), which is used for reporting the status of the button and syncing button settings, rather than an [Event message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#event-message) or an [Alert message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#alert-message).

### Debounce

Due to the physical limitations of mechanical switches and sensors, the change in voltage detected by the Soracom LTE-M Button will often bounce up and down before settling (also called "noise"), which may result in multiple messages being triggered. You can apply a debounce in order to allow the change in voltage to settle and avoid interpreting the noise as individual triggers.

> [!NOTE]
>
> Although enabling debounce will reduce unwanted triggers, incorrect detections may still occur due to inconsistent or noisy signals caused by loose wiring, faulty switches, or other circuit component issues.
>
> When using **Pulse Detection** with debounce enabled, the Soracom LTE-M Button may not be able to detect external clicks shorter than 100ms.

### Timer Message

When the operation mode is configured as [Timer](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/timer) or [Event + Timer](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event-and-timer), the button will count the number of Single short clicks, Double short clicks, and Single long clicks. However, these detections will not be separated from clicks detected from the built-in button.

## Configuration

**Pulse Detection** can be enabled in any operation mode.

1. Follow the [Configuration](https://docs.soracom.io/en/devices/soracom-lte-m-button/configuration) instructions for configuring **Soracom LTE-M Button settings**.

2. When prompted, select **Edge Detection** for the external I/O mode, and select whether or not to enable debounce:

   ![Select Pulse Detection](https://docs.soracom.io/_astro/03-pulse-configuration.BwVPgRsU_Z2wFhNx.webp)

After configuring **Soracom LTE-M Button settings**, follow the [instructions to sync your button](https://docs.soracom.io/en/devices/soracom-lte-m-button/configuration#syncing-button-settings).

## Pin Assignment

The 2-wire accessory can be used to connect an external switch or circuit to the button. You can also prepare your own connector using a standard 3.5mm TRRS plug with the following connections:

![TRRS pin assignment](https://docs.soracom.io/_astro/04-trrs.zCOC_wCm_ZsOIoh.webp)

| Pin | Connection |
| - | - |
| **Tip** (T) | (unused) |
| **Ring 1** (R) | Sensor interrupt |
| **Ring 2** (R) | (unused) |
| **Sleeve** (S) | GND |
