Arduino driver for the TMP102 digital temperature sensor.
The TMP102 is a high-accuracy digital temperature sensor with an I²C interface designed for applications such as environmental monitoring, industrial temperature sensing, IoT devices, and thermal protection systems.
This library provides a simple interface for configuring the sensor and reading temperature values in Celsius and Fahrenheit.
-
Temperature measurement (°C)
-
Temperature measurement (°F)
-
Raw temperature register reading
-
One-shot temperature conversion
-
Shutdown power-saving mode
-
High and low temperature threshold configuration
-
Extended temperature resolution mode
-
Arduino UNO / Mega
-
ESP32
-
Any board supporting the Wire (I²C) library
- 7Semi Digital Temperature Sensor I2C Breakout - TMP102
The TMP102 communicates using I²C.
TMP102 Pin MCU Pin Description
| TMP102 Pin | MCU Pin | Description |
|---|---|---|
| VCC | 3.3V | Sensor power |
| GND | GND | Ground |
| SCL | SCL | I²C clock |
| SDA | SDA | I²C data |
- 0x48
- 0x49
- 0x4A
- 0x4B
- 100 kHz – 400 kHz
-
Open Arduino IDE
-
Go to Library Manager
-
Search for 7Semi TMP102
-
Click Install
-
Manual Installation
- Arduino IDE → Sketch → Include Library → Add .ZIP Library
#include <7Semi_TMP102.h>
TMP102_7Semi tmp;
void setup()
{
Serial.begin(115200);
if(!tmp.begin())
{
Serial.println("TMP102 not detected");
while(1);
}
}
void loop()
{
float temperature;
if(tmp.readTemperatureC(temperature))
{
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
}
delay(1000);
}float temp;
tmp.readTemperatureC(temp);
Serial.print("Temperature: ");
Serial.println(temp);Returns temperature in degrees Celsius.
float tempF;
tmp.readTemperatureF(tempF);
Serial.print("Temperature F: ");
Serial.println(tempF);Returns temperature in degrees Fahrenheit.
int16_t raw;
tmp.readRawTemperature(raw);
Serial.print("Raw Temperature: ");
Serial.println(raw);Returns raw temperature register value from the sensor.
Controls how often the sensor performs temperature conversions.
tmp.setConversionRate(TMP102_CONVERSION_RATE_4_HZ);Available conversion rates:
TMP102_CONVERSION_RATE_0_25_HZ
TMP102_CONVERSION_RATE_1_HZ
TMP102_CONVERSION_RATE_4_HZ
TMP102_CONVERSION_RATE_8_HZHigher conversion rates update temperature faster but consume more power.
Shutdown mode stops continuous conversions to reduce power consumption.
tmp.setShutdown(true);This is useful for battery-powered applications.
Trigger a single temperature conversion while in shutdown mode.
tmp.startOneShot();Useful for low power periodic measurements.
The TMP102 provides a thermostat alert system.
Example:
tmp.setHighLimit(30);
tmp.setLowLimit(20);
tmp.setAlert(true, TMP102_ALERT_ACTIVE_LOW);This configures alert thresholds and enables alert mode.
Controls how many consecutive faults must occur before an alert is triggered.
tmp.setFaultQueue(TMP102_FAULT_QUEUE_4);Available options:
TMP102_FAULT_QUEUE_1
TMP102_FAULT_QUEUE_2
TMP102_FAULT_QUEUE_4
TMP102_FAULT_QUEUE_6This helps prevent false alert triggers.
Configures the electrical behavior of the ALERT pin.
tmp.setAlertPolarity(TMP102_ALERT_ACTIVE_HIGH);Available options:
TMP102_ALERT_ACTIVE_LOW
TMP102_ALERT_ACTIVE_HIGHEnable extended temperature resolution.
tmp.setExtendedMode(true);Extended mode allows the sensor to use 13-bit temperature resolution.
-
Environmental temperature monitoring
-
Industrial temperature sensing
-
IoT devices
-
Thermal protection systems
-
HVAC monitoring
-
Data center temperature logging
-
Smart home temperature sensing