/* 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 #include 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 }