Alert pin
This example demonstrates how to use the TMP117’s ALR (Alert) pin to trigger an alert when the measured temperature goes outside a specified range. When the temperature crosses the low (20 °C) or high (28 °C) threshold, the sensor pulls the alert pin low and reports the event through the Serial Monitor.
Reading temperature with alerts
Open the Serial Monitor at 115200 baud to view temperature readings and alert messages.
#include "Soldered-TMP117.h"
#define ALERT_PIN 26
#define LOW_TEMPERATURE_ALERT 20
#define HIGH_TEMPERATURE_ALERT 28
bool alert_flag = false;
Soldered_TMP117 tmp;
void setup() {
Wire.begin();
Serial.begin(115200);
tmp.init(new_temperature);
tmp.setConvMode(TMP117_CMODE::CONTINUOUS);
tmp.setConvTime(TMP117_CONVT::C15mS5);
tmp.setAveraging(TMP117_AVE::NOAVE);
tmp.setAlertMode(TMP117_PMODE::ALERT);
tmp.setAlertCallback(temperature_alert, ALERT_PIN);
tmp.setAlertTemperature(LOW_TEMPERATURE_ALERT, HIGH_TEMPERATURE_ALERT);
}
void loop() {
tmp.update();
if (alert_flag) {
if (tmp.getAlertType() == TMP117_ALERT::HIGHALERT) {
Serial.print("High temperature alert: ");
Serial.print(tmp.getTemperature());
Serial.println(" °C");
} else if (tmp.getAlertType() == TMP117_ALERT::LOWALERT) {
Serial.print("Low temperature alert: ");
Serial.print(tmp.getTemperature());
Serial.println(" °C");
}
alert_flag = false;
}
delay(100);
}
void new_temperature() {
Serial.print("Temperature: ");
Serial.print(tmp.getTemperature());
Serial.println(" °C");
}
void temperature_alert() {
alert_flag = true;
}
Function reference
tmp.init(void (*newDataCallback) = nullptr)
Initializes communication with the TMP117 sensor and optionally registers a callback function that is triggered when new temperature data is available.
Returns value: bool, true if the sensor was successfully initialized.
tmp.setConvMode(TMP117_CMODE mode)
Sets the sensor’s conversion mode. Supported modes include CONTINUOUS (continuous readings), ONESHOT (single reading), and SHUTDOWN (low-power standby).
Returns value: None
tmp.setConvTime(TMP117_CONVT convTime)
Configures the time between temperature conversions. Shorter conversion times provide faster updates at the cost of higher power consumption.
Returns value: None
tmp.setAveraging(TMP117_AVE avg)
Sets the number of samples to average per temperature reading. Averaging can help reduce noise at the expense of speed.
Returns value: None
tmp.setAlertMode(TMP117_PMODE mode)
Configures the TMP117’s alert mode behavior. In ALERT mode, the ALR pin is triggered when the temperature crosses programmed thresholds; in THERM mode, it operates as a comparator output.
Returns value: None
tmp.setAlertCallback(void (*callback)(), int alertPin)
Registers a callback function that is executed when the alert pin changes state. The alert pin number must be specified.
Returns value: None
tmp.setAlertTemperature(float lowLimit, float highLimit)
Sets the low and high temperature thresholds for alert generation in degrees Celsius.
Returns value: None
tmp.getAlertType()
Returns the type of alert currently active — either HIGHALERT or LOWALERT — depending on which threshold was crossed.
Returns value: TMP117_ALERT, Enumeration value indicating alert type.
tmp.update()
Updates the sensor data and checks for new readings or alert conditions. Should be called regularly in the main loop.
Returns value: None
tmp.getTemperature()
Reads and returns the latest measured temperature value.
Returns value: float, Temperature in degrees Celsius.


Full example
alertPin.ino
Example that shows how to use the TMP117’s alert pin to detect high and low temperature events.