microrobotics icon

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

microrobotics | PRO | 10/19/23 10:11:16 AM UTC | 0 ⭐ | 13609 👁️ | Never ⏰ | []
Arduino |

1.17 KB

|

None

|

0 👍

/

0 👎

/*
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.
 
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.
 
Remember to connect the TF-LUNA sensor to your Arduino properly. Refer to the sensor's datasheet for the pinout and wiring details.
*/
 
#include <Wire.h>
#include <TF-Luna.h>
 
TF_Luna lidar;
 
void setup() {
  Serial.begin(115200);
  
  // Initialize the lidar sensor
  if (lidar.begin()) {
    Serial.println("TF-LUNA initialization successful");
  } else {
    Serial.println("Failed to initialize TF-LUNA");
    while (1);
  }
}
 
void loop() {
  // Read distance data
  float distance = lidar.getDistance();
  
  if (lidar.error()) {
    Serial.print("Error: ");
    Serial.println(lidar.errorString());
  } else {
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");
  }
 
  delay(500); // Adjust the delay as needed
}
 

Comments

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

    0 B

    |

    👍

    /

    👎