# Temperature Sensor

Measure and send messages with temperature readings on every click.

> [!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 **Temperature Sensor** external I/O mode allows you to connect a DS18B20 temperature sensor in order to read the current temperature when a button is clicked, or automatically at regular intervals.

![Example using Temperature Sensor](https://docs.soracom.io/_astro/01-temperature-example.C8-Et-XD_Z2oDfq5.webp)

When the operation mode is configured as [Event](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event), [Event + Timer](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event-and-timer), or [Event + Heartbeat](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event-and-heartbeat), the button will read the value of the temperature sensor each time the button is pressed (Single short click, Double short click, or Single long click) and send a corresponding [Event with Temperature message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#event-with-temperature-message).

Additionally, 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 automatically read the value of the temperature sensor at regular intervals and send a [Timer message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#timer-message) containing the temperature measurements.

> [!WARNING]
>
> [Alert](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/alert) and [Alert + Heartbeat](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/alert-and-heartbeat) modes do not support using a temperature sensor.

> [!NOTE]
>
> **Important!** The Soracom LTE-M Button provides its own voltage to power and communicate with an attached DS18B20 sensor. When building your own circuit, ensure that the sensor is wired according to the [Pin Assignment](https://docs.soracom.io/en/devices/soracom-lte-m-button/io-modes/temperature-sensor/#pin-assignment) section below.
>
> Connecting the DS18B20 sensor to an external power source may result in communication errors or damage.
>
> Additionally, ensure that the DS18B20 sensor is **not** wired for "parasitic power" mode.

## Behavior

When configured for **Temperature Sensor**, each time the Soracom LTE-M Button takes a temperature measurement, it will apply a voltage to the external I/O in order to power and communicate with the attached DS18B20 sensor. Once it receives the measurement from the sensor, the value is sent using the [Event with Temperature message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#event-with-temperature-message) and/or [Timer message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#timer-message), depending on the configured operation mode.

> [!NOTE]
>
> If the button is unable to communicate with the attached DS18B20 sensor, it will send an [Event message](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#event-message) instead of an Event with Temperature message, and the temperature measurements in Timer messages will be `0`.

### Measurement

The Soracom LTE-M Button will read the temperature measurement from an attached DS18B20 sensor using its maximum 12-bit resolution. When sending the temperature measurement, this value is rounded to the nearest 0.01 degrees (°C).

> [!WARNING]
>
> Note that although the button will report the temperature value with a precision of 0.01°C, the accuracy of the DS18B20 sensor is generally limited to ±0.5°C when measuring temperatures between -10°C and +85°C, with additionally loss in accuracy outside of that range.

### 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 send [Timer messages](https://docs.soracom.io/en/devices/soracom-lte-m-button/message-examples#timer-message) at regular intervals according to the configured **Uplink frequency**.

To provide additional granularity, each Timer message is subdivided into 5 summaries, with the duration of each summary equal to 1/5th the duration of the **Uplink frequency**.

The button will measure the temperature sensor at the end of each summary, and then report all five measurements in the Timer message, each labeled with a number from 1–5.

![Temperature sensor measurement timeline with 5 summary periods](https://docs.soracom.io/_astro/02-temperature-timer-behavior.C523CdW1_Z286bsh.webp)

> [!WARNING]
>
> For more information on the **Timer message**, refer to the [Timer Mode](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/timer) documentation.

## Configuration

**Temperature Sensor** can be enabled in [Event](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event), [Timer](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/timer), [Event + Timer](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event-and-timer), and [Event + Heartbeat](https://docs.soracom.io/en/devices/soracom-lte-m-button/operation-modes/event-and-heartbeat) operation modes.

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 **Temperature Sensor** for the external I/O mode:

   ![Select Temperature Sensor](https://docs.soracom.io/_astro/03-temperature-configuration.DrN3ph1f_ZFXUTY.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

A DS18B20 temperature sensor should be connected to button using a 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) | VDD |
| **Ring 1** (R) | (unused) |
| **Ring 2** (R) | Data I/O (DQ) |
| **Sleeve** (S) | GND |
