Advertisement
microrobotics

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

Oct 19th, 2023
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. /*
  2. 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.
  3.  
  4. 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.
  5.  
  6. Remember to connect the TFmini sensor to your Arduino properly. Refer to the sensor's datasheet for the pinout and wiring details.
  7. */
  8.  
  9. #include <Wire.h>
  10. #include <TFmini.h>
  11.  
  12. TFmini tfmini;
  13.  
  14. void setup() {
  15.   Serial.begin(115200);
  16.  
  17.   // Initialize the TFmini sensor
  18.   if (tfmini.begin()) {
  19.     Serial.println("TFmini initialization successful");
  20.   } else {
  21.     Serial.println("Failed to initialize TFmini");
  22.     while (1);
  23.   }
  24. }
  25.  
  26. void loop() {
  27.   // Read distance data
  28.   uint16_t distance = tfmini.getDistance();
  29.  
  30.   if (tfmini.error()) {
  31.     Serial.print("Error: ");
  32.     Serial.println(tfmini.errorString());
  33.   } else {
  34.     Serial.print("Distance: ");
  35.     Serial.print(distance);
  36.     Serial.println(" cm");
  37.   }
  38.  
  39.   delay(100); // Adjust the delay as needed
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement