Created
October 7, 2026 11:43
-
-
Save Robotto/fe24bf28e1c8cd9e739400a49749278a to your computer and use it in GitHub Desktop.
TFmini Lidar TOF sensor on ESP32 (Wemos D1 mini ESP32)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Library: http://librarymanager/All#TFMini - By Peter Jansen - https://github.com/opensensinglab/tfmini | |
| //Define pins for UART2 - They can be almost any pins. | |
| #define RXD2 16 | |
| #define TXD2 17 | |
| #include "TFMini.h" | |
| HardwareSerial mySerial(2); | |
| TFMini tfmini; | |
| void setup() { | |
| // Step 1: Initialize hardware serial port (serial debug port) | |
| Serial.begin(115200); | |
| Serial.println ("Initializing..."); | |
| // Step 2: Initialize the data rate, mode, and pins for the ESP32's UART2 | |
| mySerial.begin(TFMINI_BAUDRATE, SERIAL_8N1, RXD2, TXD2); | |
| // Step 3: Initialize the TF Mini sensor, point it to the mySerial object representing UART2 | |
| tfmini.begin(&mySerial); | |
| } | |
| void loop() { | |
| // Take one TF Mini distance measurement | |
| uint16_t dist = tfmini.getDistance(); | |
| uint16_t strength = tfmini.getRecentSignalStrength(); | |
| // Display the measurement | |
| Serial.print(dist); | |
| Serial.print(" cm sigstr: "); | |
| Serial.println(strength); | |
| // Wait some short time before taking the next measurement | |
| delay(5); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment