TOF10120 Laser Distance (Time of Flight) Sensor

View on Amazon
Overview
About TOF10120 Laser Distance (Time of Flight) Sensor
The TOF10120 is a compact laser distance sensor that uses Time-of-Flight (TOF) technology for accurate and reliable distance measurements. With a measurement range of up to 180 cm and support for I²C and UART communication, it is ideal for robotics, obstacle detection, and proximity sensing applications.
⚡ Key Features
- Accurate Distance Measurement – Measures 10 cm to 180 cm with ±2 cm precision.
- Dual Communication Interface – Supports I²C and UART for flexible integration.
- Low Power Consumption – Operates at <30mA, making it ideal for battery-powered applications.
- Wide Voltage Compatibility – Works with 3.3V to 5V, fully compatible with ESP32 and other microcontrollers.
With its compact design and reliable TOF technology, the TOF10120 is a great choice for embedded systems and robotics applications requiring precise distance sensing. 🚀
Get Your TOF10120
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
TOF10120 Specifications
Complete technical specification details for TOF10120 Laser Distance (Time of Flight) Sensor
📊 Technical Parameters
TOF10120 Pinout
The TOF10120 features 6 pins supporting both I²C and UART communication modes for flexible integration.
Visual Pinout Diagram

Pin Types
Quick Tips
Supports both I²C and UART communication,📡 I²C address is 0x52 (fixed)
Choose protocol based on your application needs,⚡ Low power consumption (<30mA)
Measures 10-180cm with ±2cm accuracy
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply input (3.3V to 5V) | Compatible with both 3.3V and 5V systems |
2 GND | Power | Ground connection | Connect to ESP32 ground |
3 SDA | Communication | I²C data line | Bidirectional data for I²C mode |
4 SCL | Communication | I²C clock line | Clock signal for I²C mode |
5 TX | Communication | UART transmit pin | Serial data output for UART mode |
6 RX | Communication | UART receive pin | Serial data input for UART mode |
Wiring TOF10120 to ESP32
Connect the TOF10120 using I²C mode for multi-device bus sharing and easy integration.
Visual Wiring Diagram

Connection Status
Protocol

Pin Connections
| TOF10120 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply (3.3V or 5V) | |
2 GND Required | GND | Ground connection | |
3 SDA Required | GPIO21 | I²C data line (default SDA) | |
4 SCL Required | GPIO22 | I²C clock line (default SCL) |
GPIO21/22 are default I²C pins on ESP32
I²C address is 0x52 (not configurable)
Most modules have built-in pull-up resistors
Can share I²C bus with other devices
TOF10120 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The TOF10120 sensor provides fluctuating or inaccurate distance readings, even when the target object is stationary.
Possible causes include electrical noise, improper sensor alignment, or interference from ambient light sources.
Solution: Ensure that the sensor is properly aligned perpendicular to the target surface to receive accurate reflections. Minimize exposure to strong ambient light, especially direct sunlight, which can interfere with the sensor's infrared measurements. Implement filtering algorithms, such as averaging multiple readings, to mitigate the effects of occasional erroneous data.
Issue: The TOF10120 sensor is not recognized on the I2C bus, leading to communication failures.
Possible causes include incorrect I2C address configuration, improper wiring, or lack of pull-up resistors on the I2C lines.
Solution: Verify that the sensor's I2C address matches the address specified in your code; the default address is 0x52. Ensure that the SDA and SCL lines are correctly connected to the corresponding pins on the microcontroller. Check for the presence of appropriate pull-up resistors (typically 4.7kΩ) on the I2C lines if they are not already included on the sensor module.
Issue: When using multiple TOF10120 sensors simultaneously, their signals interfere with each other, causing inaccurate readings.
Possible causes include identical I2C addresses for all sensors or overlapping measurement zones.
Solution: Since the TOF10120 sensor has a fixed I2C address, using multiple sensors on the same bus requires additional hardware, such as an I2C multiplexer, to manage communication. Alternatively, consider using the sensor's UART mode for communication, assigning different serial ports for each sensor. Physically space the sensors apart to prevent their measurement zones from overlapping, reducing the chance of cross-talk interference.
Issue: The sensor outputs values that do not correspond to the actual distance, even when the sensor is completely blocked or no object is present.
Possible causes include incorrect data parsing, sensor malfunction, or improper initialization.
Solution: Review the data parsing logic in your code to ensure it correctly interprets the sensor's output format. Confirm that the sensor is properly initialized and that any required calibration procedures are followed. If the issue persists, test the sensor with a known working setup to determine if it is functioning correctly or needs replacement.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
TOF10120 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#define TOF10120_ADDR 0x52
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("TOF10120 Distance Sensor Example");
}
void loop() {
uint16_t distance = getDistance();
if (distance != 0) {
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" mm");
} else {
Serial.println("Sensor error or no object detected.");
}
delay(500);
}
uint16_t getDistance() {
Wire.beginTransmission(TOF10120_ADDR);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(TOF10120_ADDR, 2);
if (Wire.available() == 2) {
uint16_t distance = Wire.read() << 8 | Wire.read();
return distance;
}
return 0;
}0x52). The getDistance() function sends a request to the sensor to initiate a distance measurement and then reads the resulting two-byte data. The calculated distance (in millimeters) is displayed on the Serial Monitor, with a 500 ms delay between readings.#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_FREQ_HZ 100000
#define TOF10120_ADDR 0x52
static const char *TAG = "TOF10120";
void app_main() {
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &i2c_config));
ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, I2C_MODE_MASTER, 0, 0, 0));
uint8_t data[2];
while (1) {
i2c_master_write_to_device(I2C_MASTER_NUM, TOF10120_ADDR, NULL, 0, 1000 / portTICK_PERIOD_MS);
i2c_master_read_from_device(I2C_MASTER_NUM, TOF10120_ADDR, data, 2, 1000 / portTICK_PERIOD_MS);
uint16_t distance = (data[0] << 8) | data[1];
ESP_LOGI(TAG, "Distance: %d mm", distance);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}0x52). A loop sends a command to read distance data from the sensor and parses the response into a 16-bit distance value (in millimeters). The distance is logged every 500 ms. Error handling ensures the loop continues if communication issues occur.sensor:
- platform: tof10120
name: "TOF10120 Distance"
update_interval: 500mstof10120 platform to interface with the sensor. The name assigns a user-friendly label ('TOF10120 Distance') to the sensor data, making it identifiable in smart home platforms. The update_interval is set to 500 ms for frequent distance updates.platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200main.cpp
#include <Wire.h>
#define TOF10120_ADDR 0x52
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("TOF10120 Distance Sensor Example");
}
void loop() {
uint16_t distance = getDistance();
if (distance != 0) {
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" mm");
} else {
Serial.println("Sensor error or no object detected.");
}
delay(500);
}
uint16_t getDistance() {
Wire.beginTransmission(TOF10120_ADDR);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(TOF10120_ADDR, 2);
if (Wire.available() == 2) {
uint16_t distance = Wire.read() << 8 | Wire.read();
return distance;
}
return 0;
}getDistance() function sends a command to the sensor and retrieves a 2-byte distance value, which is then displayed on the Serial Monitor every 500 ms. The 0x52 I2C address is used for communication. This example is compatible with Arduino-compatible ESP32 boards using the PlatformIO environment.from machine import I2C, Pin
from time import sleep
# Initialize I2C communication (SDA = GPIO21, SCL = GPIO22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# TOF10120 I2C Address
tof_address = 0x52
def read_distance():
# Request distance measurement
i2c.writeto(tof_address, b'\x00')
data = i2c.readfrom(tof_address, 2)
# Parse two-byte response
distance = (data[0] << 8) | data[1]
return distance
print("TOF10120 Distance Sensor Example")
while True:
distance = read_distance()
print("Distance: {} mm".format(distance))
sleep(0.5)read_distance() function sends a command to the sensor and reads a 2-byte response, converting it to a 16-bit distance value. The distance is displayed on the console every 500 ms.Wrapping Up TOF10120
The ESP32 TOF10120 Laser Distance (Time of Flight) Sensor is a powerful distance sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the TOF10120 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the TOF10120? Check out these similar sensors that might fit your project needs.
The A02YYUW is a waterproof ultrasonic distance sensor ideal for outdoor and industrial applications. With a measuring range of up to 4.5...
The GY-530 is a breakout board for the VL53L0X Time-of-Flight (ToF) sensor from STMicroelectronics. It uses FlightSense technology to...








