Advertisement
microrobotics

Benewake TF-LUNA Industrial Lidar Range Sensor 0.2-8m

Oct 19th, 2023
1,792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Make sure you have the TF-LUNA library installed. To install it, open the Arduino IDE, go to "Sketch" -> "Include Library" -> "Manage Libraries...". In the Library Manager, search for "TF-Luna" and install the library.
  3.  
  4. This code initializes the TF-LUNA 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 TF-LUNA 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 <TF-Luna.h>
  11.  
  12. TF_Luna lidar;
  13.  
  14. void setup() {
  15.   Serial.begin(115200);
  16.  
  17.   // Initialize the lidar sensor
  18.   if (lidar.begin()) {
  19.     Serial.println("TF-LUNA initialization successful");
  20.   } else {
  21.     Serial.println("Failed to initialize TF-LUNA");
  22.     while (1);
  23.   }
  24. }
  25.  
  26. void loop() {
  27.   // Read distance data
  28.   float distance = lidar.getDistance();
  29.  
  30.   if (lidar.error()) {
  31.     Serial.print("Error: ");
  32.     Serial.println(lidar.errorString());
  33.   } else {
  34.     Serial.print("Distance: ");
  35.     Serial.print(distance);
  36.     Serial.println(" cm");
  37.   }
  38.  
  39.   delay(500); // Adjust the delay as needed
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement