The 16304-SparkFun Qwiic TMP102 Digital Temp Sensor is a high-precision digital temperature sensor designed for easy integration into projects and products. Utilizing the TMP102 sensor chip, this breakout board is ideal for environmental temperature sensing for home automation, industrial systems, and weather stations. Its Qwiic connector system enables quick, solderless connection to other Qwiic-compatible devices, making it a convenient choice for rapid prototyping and educational purposes.
Pin Number | Name | Description |
---|---|---|
1 | GND | Ground connection |
2 | VCC | Power supply (1.4V to 3.6V) |
3 | SDA | I2C Data line |
4 | SCL | I2C Clock line |
5 | ADD0 | Address select pin |
6 | ALRT | Alert pin |
#include <Wire.h>
// TMP102 I2C address is 0x48 (default)
#define Addr 0x48
void setup() {
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x01);
// Set continuous conversion mode, 12-bit resolution
Wire.write(0x60);
// Stop I2C Transmission
Wire.endTransmission();
delay(300);
}
void loop() {
unsigned int data[2];
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp msb, temp lsb
if (Wire.available() == 2) {
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 12-bits
int temp = ((data[0] * 256) + (data[1] & 0xF0)) / 16;
if (temp > 2047) {
temp -= 4096;
}
float celsius = temp * 0.0625;
float fahrenheit = (celsius * 1.8) + 32;
// Output data to serial monitor
Serial.print("Temperature in Celsius: ");
Serial.print(celsius);
Serial.println(" C");
Serial.print("Temperature in Fahrenheit: ");
Serial.print(fahrenheit);
Serial.println(" F");
delay(500);
}
Q: Can the sensor be used with a 5V system? A: While the sensor operates at 1.4V to 3.6V, level shifters can be used for interfacing with a 5V system.
Q: How can I change the I2C address of the sensor? A: The I2C address can be changed by connecting the ADD0 pin to GND, VCC, SDA, or SCL, corresponding to addresses 0x48, 0x49, 0x4A, or 0x4B, respectively.
Q: What is the maximum distance for the I2C bus? A: I2C is typically used for short distances, but with proper bus buffering and termination, longer distances can be achieved. Keep the lines as short as possible for reliable communication.