microrobotics icon

Benewake TFmini-S Industrial LiDAR Range Sensor 0.1-12m

microrobotics | PRO | 10/19/23 10:15:25 AM UTC | 0 ⭐ | 14682 👁️ | Never ⏰ | []
C |

1.17 KB

|

None

|

0 👍

/

0 👎

/*
Make sure you have the TFmini library installed. To install it, open the Arduino IDE, go to "Sketch" -> "Include Library" -> "Manage Libraries...". In the Library Manager, search for "TFmini" and install the library.
 
This code initializes the TFmini sensor and reads the distance data in a loop, printing it to the serial monitor. Adjust the delay in the loop according to your requirements.
 
Remember to connect the TFmini sensor to your Arduino properly. Refer to the sensor's datasheet for the pinout and wiring details.
*/
 
#include <Wire.h>
#include <TFmini.h>
 
TFmini tfmini;
 
void setup() {
  Serial.begin(115200);
  
  // Initialize the TFmini sensor
  if (tfmini.begin()) {
    Serial.println("TFmini initialization successful");
  } else {
    Serial.println("Failed to initialize TFmini");
    while (1);
  }
}
 
void loop() {
  // Read distance data
  uint16_t distance = tfmini.getDistance();
  
  if (tfmini.error()) {
    Serial.print("Error: ");
    Serial.println(tfmini.errorString());
  } else {
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");
  }
 
  delay(100); // Adjust the delay as needed
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎