Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement