Quantcast
Viewing all articles
Browse latest Browse all 1123

TMP102 Digital Temperature Sensor Hookup Guide

TMP102 Digital Temperature Sensor Hookup Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t540

Introduction

The TMP102 is an easy-to-use digital temperature sensor from Texas Instruments. While some temperature sensors use an analog voltage to represent the temperature, the TMP102 uses the I2C bus of the Arduino to communicate the temperature.

SEN-13314
4.95

Required Materials

To follow along with this hookup guide, you will need the following:

Suggested Reading

Before getting started, you may find the following links useful:

Board Overview

Let’s go over the TMP102 Breakout in detail.

Image may be NSFW.
Clik here to view.
alt text

TMP102 Details:

  • Uses the I2C interface
  • 12-bit, 0.0625°C resolution
  • Typical temperature accuracy of ±0.5°C
  • 3.3V sensor - use inline logic level converters or 10 kΩ resistors to limit 5V signals
  • Supports up to four TMP102 sensors on the I2C bus at a time

Pull-up Resistors

This breakout board has built-in 4.7 kΩ pull up resistors for I2C communications. If you’re hooking up multiple I2C devices on the same bus, you may want to disable/enable the pull-up resistors for one or more boards. On the TMP102, the pull-ups are enabled by default. To disable them, simply use a hobby knife to cut the traces connecting the left and right pads of the jumper labeled I2C PU on the back of the board. This will disconnect the resistors from VCC and from the I2C bus.

Hardware Connections

Connecting the TMP102 to an Arduino

Wiring the TMP102 is very easy! We recommend soldering six male headers to the breakout board. You can also solder wires to fit your application’s needs.

Power

This board runs from 1.4V to 3.6V. Be sure to power the board from the 3.3V pin! I2C uses an open drain signaling, so there is no need to use level shifting; the 3.3V signal will work to communicate with the Arduino and will not exceed the maximum voltage rating of the pins on the TMP102.

Connections to the Arduino

The TMP102 breakout board has six pins, however we’ll only be using five of the pins in today’s example. We’ll be connecting VCC and GND to the normal power pins, two data lines for I2C communication, and one digital pin to see if there is an alert. If you’re using a newer board that has SDA and SCL broken out, you can connect the SDA and SCL pins directly to those pins. If you’re using an older board, SDA and SCL are pins A4 and A5 respectively.

  • VCC → 3.3V
  • GND → GND
  • SDA → SDA/A4
  • SCL → SCL/A5
  • ALT → A3

This would looks something like this:

Image may be NSFW.
Clik here to view.
alt text

The only pin that we aren’t using is ADD0, this pin is used to change the address of the TMP102. If you’re using multiple TMP102s or another device that uses that address, you’ll want to use this pin to change the address. The default address is 0x48. You can change the address by connecting an external jumper wire to the following pins:

  • VCC → 0x49
  • SDA → 0x4A
  • SCL → 0x4B

TMP102 Library and Example Code

Note:This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review ou tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

To get started immediately, use the example code and library files below.

language:c
/******************************************************************************
TMP102_example.ino
Example for the TMP102 I2C Temperature Sensor
Alex Wende @ SparkFun Electronics
April 29th 2016
~

This sketch configures the TMP102 temperature sensor and prints the
temperature and alert state (both from the physical pin, as well as by
reading from the configuration register.

Resources:
Wire.h (included with Arduino IDE)
SparkFunTMP102.h

Development environment specifics:
Arduino 1.0+
Hardware Version 13

This code is beerware; if you see me (or any other SparkFun employee) at
the local, and you've found our code helpful, please buy us a round!

Distributed as-is; no warranty is given.
******************************************************************************/

#include <Wire.h> // Used to establied serial communication on the I2C bus
#include "SparkFunTMP102.h" // Used to send and recieve specific information from our sensor

// Connections
// VCC = 3.3V
// GND = GND
// SDA = A4
// SCL = A5
const int ALERT_PIN = A3;

TMP102 sensor0(0x48); // Initialize sensor at I2C address 0x48
// Sensor address can be changed with an external jumper to:
// ADD0 - Address
//  VCC - 0x49
//  SDA - 0x4A
//  SCL - 0x4B

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud
  pinMode(ALERT_PIN,INPUT);  // Declare alertPin as an input
  sensor0.begin();  // Join I2C bus

  // Initialize sensor0 settings
  // These settings are saved in the sensor, even if it loses power

  // set the number of consecutive faults before triggering alarm.
  // 0-3: 0:1 fault, 1:2 faults, 2:4 faults, 3:6 faults.
  sensor0.setFault(0);  // Trigger alarm immediately

  // set the polarity of the Alarm. (0:Active LOW, 1:Active HIGH).
  sensor0.setAlertPolarity(1); // Active HIGH

  // set the sensor in Comparator Mode (0) or Interrupt Mode (1).
  sensor0.setAlertMode(0); // Comparator Mode.

  // set the Conversion Rate (how quickly the sensor gets a new reading)
  //0-3: 0:0.25Hz, 1:1Hz, 2:4Hz, 3:8Hz
  sensor0.setConversionRate(2);

  //set Extended Mode.
  //0:12-bit Temperature(-55C to +128C) 1:13-bit Temperature(-55C to +150C)
  sensor0.setExtendedMode(0);

  //set T_HIGH, the upper limit to trigger the alert on
  sensor0.setHighTempF(85.0);  // set T_HIGH in F
  //sensor0.setHighTempC(29.4); // set T_HIGH in C

  //set T_LOW, the lower limit to shut turn off the alert
  sensor0.setLowTempF(84.0);  // set T_LOW in F
  //sensor0.setLowTempC(26.67); // set T_LOW in C
}

void loop()
{
  float temperature;
  boolean alertPinState, alertRegisterState;

  // Turn sensor on to start temperature measurement.
  // Current consumtion typically ~10uA.
  sensor0.wakeup();

  // read temperature data
  temperature = sensor0.readTempF();
  //temperature = sensor0.readTempC();

  // Check for Alert
  alertPinState = digitalRead(ALERT_PIN); // read the Alert from pin
  alertRegisterState = sensor0.alert();   // read the Alert from register

  // Place sensor in sleep mode to save power.
  // Current consumtion typically <0.5uA.
  sensor0.sleep();

  // Print temperature and alarm state
  Serial.print("Temperature: ");
  Serial.print(temperature);

  Serial.print("\tAlert Pin: ");
  Serial.print(alertPinState);

  Serial.print("\tAlert Register: ");
  Serial.println(alertRegisterState);

  delay(1000);  // Wait 1000ms
}

You can download the library from the link below.

TMP102 Arduino Library

Once the library is installed, open Arduino, and expand the examples menu. You should see the TMP102 example.

Image may be NSFW.
Clik here to view.
alt text

TMP102 Functions

Main functions

These are functions used to read settings and temperatures from the sensor.

TMP102::readTempC() - Returns the current temperature in Celsius.

TMP102::readTempF() - Returns the current temperature in Fahrenheit.

TMP102::readLowTempC(float temperature) - Reads T_LOW register in Celsius.

TMP102::readHighTempC(float temperature) - Reads T_HIGH register in Celsius.

TMP102::readLowTempF(float temperature) - Reads T_LOW register in Fahrenheit.

TMP102::readHighTempF(float temperature) - Reads T_HIGH register in Fahrenheit.

TMP102::sleep() - Put TMP102 in low power mode (<0.5 uA).

TMP102::wakeup() - Return to normal power mode (~10 uA). When the sensor powers up, it is automatically running in normal power mode, and only needs to be used after TMP102::sleep() is used.

TMP102::alert() - Returns the state of the Alert register. The state of the register is the same as the ALT pin.

Nonvolatile Functions

These are settings that are saved in the sensor, even after power is removed.

TMP102::setLowTempC(float temperature) - Sets T_LOW (in Celsius) alert threshold.

TMP102::setHighTempC(float temperature) - Sets T_HIGH (in Celsius) alert threshold.

TMP102::setLowTempF(float temperature) - Sets T_LOW (in Fahrenheit) alert threshold.

TMP102::setHighTempF(float temperature) - Sets T_HIGH (in Fahrenheit) alert threshold.

TMP102::setConversionRate(byte rate) - Sets the temperature reading conversion rate. 0: 0.25Hz, 1: 1Hz, 2: 4Hz (default), 3: 8Hz.

TMP102::setExtendedMode(byte mode) - Enable or disable extended mode. 0: disabled (-55C to +128C), 1: enabled (-55C to +150C).

TMP102::setAlertPolarity(bool polarity) - Sets the polarity of the alert. 0: active LOW, 1: active HIGH

TMP102::setFault(byte faultSetting) - Sets the number of consecutive faults before triggering alert. 0: 1 fault, 1: 2 faults, 2: 4 faults, 3: 6 faults.

TMP102::setAlertMode(bool mode) - Sets the type of alert. 0: Comparator Mode (Active from when temperature > T_HIGH until temperature < T_LOW), 1: Thermostat mode (Active from when temperature > T_HIGH until any read operation occurs.

Resources and Going Further

For more information about the TMP102 Breakout, check out the links below.

For more sensor fun, check out these other great SparkFun tutorials.

Hackers in Residence - Hacking MindWave Mobile

Review, teardown, and hacking tutorial for the MindWave Mobile, a $99 commercial grade EEG sensor.

VL6180 Hookup Guide

Get started with your VL6180 based sensor or the VL6180 breakout board.

Blynk Board Washer/Dryer Alarm

How to configure the Blynk Board and app to notify you when your washer or dryer is done shaking.

SoftPot Hookup Guide

Equip your Arduino project with a sliding soft potentiometer to monitor position or adding linear control to your project.

learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado


Viewing all articles
Browse latest Browse all 1123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>