Using the TMP117 with Arduino is a simple matter of wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit TMP117 library we've written, and running the provided example code.

I2C Wiring

Use this wiring if you want to connect via I2C interface. The default I2C address for the TMP117 is 0x48 but it can be switched to 0x49 by pulling the address pin high to VCC. 

Here is how to wire up the sensor using one of the STEMMA QT connectors. The examples show a Metro but wiring will work the same for an Arduino or other compatible board.

  • Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
  • Connect board GND (black wire) to Arduino GND
  • Connect board SCL (yellow wire) to Arduino SCL
  • Connect board SDA (blue wire) to Arduino SDA

Here is how to wire the sensor to a board using a solderless breadboard:

  • Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
  • Connect board GND (black wire) to Arduino GND
  • Connect board SCL (yellow wire) to Arduino SCL
  • Connect board SDA (blue wire) to Arduino SDA

Library Installation

You can install the Adafruit TMP117 library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for Adafruit TMP117 , and select the Adafruit TMP117 library:

Follow the same process for the Adafruit BusIO library.

Finally follow the same process for the Adafruit Unified Sensor library:

Load Basic Example

Open up File -> Examples ->Adafruit TMP117 -> basic_test

After opening the demo file, upload to your Arduino wired up to the sensor. Once you upload the code, you will see the Temperature values being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:

Basic Example Code

/**
 * @file basic_test.ino
 * @author Bryan Siepert for Adafruit Industries
 * @brief Shows how to specify a
 * @date 2020-11-10
 * 
 * @copyright Copyright (c) 2020
 * 
 */
#include <Wire.h>
#include <Adafruit_TMP117.h>
#include <Adafruit_Sensor.h>

Adafruit_TMP117  tmp117;
void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens
  Serial.println("Adafruit TMP117 test!");

  // Try to initialize!
  if (!tmp117.begin()) {
    Serial.println("Failed to find TMP117 chip");
    while (1) { delay(10); }
  }
  Serial.println("TMP117 Found!");

}
void loop() {

  sensors_event_t temp; // create an empty event to be filled
  tmp117.getEvent(&temp); //fill the empty event object with the current measurements
  Serial.print("Temperature  "); Serial.print(temp.temperature);Serial.println(" degrees C");
  Serial.println("");

  delay(1000);
}

 In addition to the basic examples, we have a few other options in the examples directory, including one for using the build in alerts.

Load Alerts Example

Open up File -> Examples -> Adafruit TMP117 -> alerts

You may want to adjust the high and low temperature limits to fit your conditions to see how they trigger. If the default values don't work for your setup, changing the argument for setLowThreshold and setHighThreshold will specify a new temperature to use.

Download: file
// You may need to adjust these thresholds to fit the temperature range of where the test is
// being run to be able to see the alert status change.
tmp117.setHighThreshold(35.0);
Serial.print("High threshold: "); Serial.println(tmp117.getHighThreshold(), 1);
tmp117.setLowThreshold(28.5);
Serial.print("Low threshold: "); Serial.println(tmp117.getLowThreshold(), 1);

Once any adjustments are made, the file should be compiled and uploaded to your connected board. Once finished, you can see the temperature being reported along with the states of the two alerts.

Once you've got the alerts triggering, try changing the code below to enable or disable "Therm" mode which makes the thresholds work more like a target temperature and hysteresis value to designate the lower bounds of the acceptable temperature range.

Download: file
// Set the enable flag below to see how the low temp limit can be used as a
// hysteresis value that defines the acceptable range for the temperature values where
// the high temp alert is not active
tmp117.thermAlertModeEnabled(true);

Alerts Example Code

/**
 * @file alerts.ino
 * @author Bryan Siepert for Adafruit Industries
 * @brief Show how to set adjust and use the sensor's included alert settings
 * @date 2020-11-10
 * 
 * @copyright Copyright (c) 2020
 * 
 */
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TMP117.h>
#include <Wire.h>

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

Adafruit_TMP117 tmp117;
void setup(void) {
  Serial.begin(115200);
  while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens
  Serial.println("Adafruit TMP117 test!");

  // Try to initialize!
  if (!tmp117.begin()) {
    Serial.println("Failed to find TMP117 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("TMP117 Found!");

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ; // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.display();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setRotation(0);

  // Set the enable flag below to see how the low temp limit can be used as a
  // hysteresis value that defines the acceptable range for the temperature values where
  // the high temp alert is not active
  // tmp117.thermAlertModeEnabled(true);
  Serial.print("Therm mode enabled: ");
  if (tmp117.thermAlertModeEnabled()) {
    Serial.println("True");
  } else {
    Serial.println("False");
  }

  // You may need to adjust these thresholds to fit the temperature range of where the test is
  // being run to be able to see the alert status change.
  tmp117.setHighThreshold(35.0);
  Serial.print("High threshold: "); Serial.println(tmp117.getHighThreshold(), 1);
  tmp117.setLowThreshold(28.5);
  Serial.print("Low threshold: "); Serial.println(tmp117.getLowThreshold(), 1);

  // tmp117.interruptsActiveLow(false);
  if(tmp117.interruptsActiveLow()){
    Serial.println("Alerts are active when the INT pin is LOW");
  } else {
    Serial.println("Alerts are active when the INT pin is HIGH");
  }

  Serial.println("");
  Serial.println("");
}

void loop() {
  display.clearDisplay();
  display.setCursor(0, 0);

  tmp117_alerts_t alerts;
  sensors_event_t temp;
  // Reading temp clears alerts, so read alerts first
  tmp117.getAlerts(&alerts); // get the status of any alerts
  tmp117.getEvent(&temp);   // get temperature

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" degrees C");

  Serial.print("High temperature alert active:");
  if (alerts.high) {
    Serial.println("True");
  } else {
    Serial.println("False");
  }

  Serial.print("Low temperature alert active:");
  if (alerts.low) {
    Serial.println("True");
  } else {
    Serial.println("False");
  }
  Serial.println("");

  //       Print to OLED
  display.print("Tmp:");
  display.print(temp.temperature, 1);
  display.println(" C");

  display.print("HI:");
  if (alerts.high) {
    display.print("Y");
  } else {
    display.print("N");
  }

  display.print(" LOW:");
  if (alerts.low) {
    display.println("Y");
  } else {
    display.println("N");
  }

  display.display();
  delay(300);
}

This guide was first published on Dec 02, 2020. It was last updated on Dec 02, 2020.

This page (Arduino) was last updated on Apr 10, 2021.

Text editor powered by tinymce.