Arduino
Using the TMF8806 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_TMF8806 library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout using the STEMMA QT connector:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
Library Installation
You can install the Adafruit_TMF8806 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_TMF8806, and select the Adafruit TMF8806 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
/*!
* @file tmf8806_simpletest.ino
*
* Simple example for the Adafruit TMF8806 Time-of-Flight sensor.
* Reads distance continuously and prints results to Serial.
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
* BSD license, all text here must be included in any redistribution.
*/
#include <Adafruit_TMF8806.h>
Adafruit_TMF8806 tof;
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println(F("TMF8806 Time-of-Flight Sensor Test"));
if (!tof.begin()) {
Serial.println(F("Failed to find TMF8806 sensor!"));
while (1) {
delay(10);
}
}
Serial.println(F("TMF8806 found!"));
// Print chip ID and revision
uint8_t chipId = tof.getChipID();
Serial.print(F("Chip ID: 0x"));
Serial.println(chipId, HEX);
Serial.print(F("Revision ID: "));
Serial.println(tof.getRevisionID());
// Print firmware version
uint8_t major, minor, patch;
tof.getVersion(&major, &minor, &patch);
Serial.print(F("Firmware version: "));
Serial.print(major);
Serial.print(F("."));
Serial.print(minor);
Serial.print(F("."));
Serial.println(patch);
// Read and print serial number
uint8_t serial[4];
if (tof.readSerialNumber(serial, 4)) {
Serial.print(F("Serial number: 0x"));
for (int i = 3; i >= 0; i--) {
if (serial[i] < 0x10) {
Serial.print(F("0"));
}
Serial.print(serial[i], HEX);
}
Serial.println();
}
// Configure sensor (optional - defaults work well)
tof.setDistanceMode(TMF8806_MODE_2_5M); // 2.5m mode (default)
tof.setIterations(400); // 400k iterations
tof.setRepetitionPeriod_ms(33); // ~30Hz
// Start continuous measurement
if (!tof.startMeasuring(true)) {
Serial.println(F("Failed to start measurement!"));
while (1) {
delay(10);
}
}
Serial.println(F("Measuring..."));
Serial.println();
}
void loop() {
if (tof.dataReady()) {
tmf8806_result_t result;
if (tof.readResult(&result) && result.reliability > 0) {
Serial.print(F("Distance: "));
Serial.print(result.distance);
Serial.print(F(" mm"));
Serial.print(F(" Reliability: "));
Serial.print(result.reliability);
Serial.print(F(" Temp: "));
Serial.print(result.temperature);
Serial.println(F(" C"));
}
}
delay(10);
}
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the TMF8806 recognized over I2C. Then, the distance in mm, reliability of the measurement and die temperature in Celcius will be printed whenever data is ready.
Page last edited September 10, 2026
Text editor powered by tinymce.