Hello, new to the forum, and I am trying to obtain readings from a TF03 Benewake sensor using the Uno board. The idea is to use the sensor as a camera trigger. I have the camera trigger part figured out, but am not able to get distance readings from the sensor, it is only showing a distance of 0 on the Serial Monitor. This is the initial code that I have been trying, found on this page:
[TF03 (ToF) Laser Range Sensor(100m/180m)]
This is also a source that i have been using:
https://paulillsley.com/arduino/lidar_camera_trigger.html
I also installed the TF Mini Library that apparently also works with this sensor. Also used the wiring information provided by the manufacturer, and supplying the required 5v of power to the TF03 sensor via the board (verified with multimeter). Also experimented with lower baud rates.
Bellow is the last code that I tried to use, any assistance would be greatly appreciated.
//------------- Code Starts Here ----------------------------
//-----------------------------------------
//Published by:
//Created by:
//-----------------------------------------
//======================= Start of Settings ===================
// *** Set the Minimum Distance trigger value (in cm) ***
int Minimum_Distance = 10;
// *** Set the Maximum Distance trigger value (in cm) ***
int Maximum_Distance = 600;
// *** Set the Delay value to wait for the camera's flash to recharge (in seconds) ***
int delay_seconds = 5;
//======================= End of Settings ====================
#include <Arduino.h>
#include <Wire.h> // Including the Wire library
#include <DFRobot_TFmini.h> // Including the TFmini Library (this needs to be installed)
DFRobot_TFmini tf03;
//Defining pin 13 for the Confirmation LED
#define LED 13
// Defining pin 4 for the Camera "Trigger" setup
#define Trigger 4
int16_t Distance_cm; // distance in centimeters
void setup(){
Serial.begin(115200); // Initalizing the Serial Port at a baud rate of 115200
delay(20);
Wire.begin(); // Initalizing the Wire Library
// setting pin 13 (the LED) as an output (this is also the pin for the UNO's on-board LED).
pinMode(13,OUTPUT);
pinMode(4,OUTPUT);
// Turning pin 4 (Trigger) off
digitalWrite(Trigger , LOW);
}
void loop(){
digitalWrite(LED , LOW); // Turning off the LED (Pin 13)
// Pulling a distance value (in cm) from the TF03
tf03.getDistance();//Distance_cm, tfAddr);
// Write the distance to the serial monitor
Serial.print("Distance (cm): ");
Serial.println(Distance_cm);
// Checking the distance for "In Trigger Zone" LED
// If the distance is above or equal to the Minimum and below or equal to the Maximum
// turn on the LED
if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
digitalWrite(LED , HIGH); // Turning on the LED (Pin 13)
}
else{
digitalWrite(LED , LOW); // Turning off the LED (Pin 13)
}
// Checking the distance for Camera Trigger
// If the distance is above or equal to the Minimum and below or equal to the Maximum
if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
// Record an image (Trigger)
digitalWrite(Trigger , HIGH); // Turning on pin 4 (Trigger)
delay(100); // Delaying 100 milliseconds
digitalWrite(Trigger , LOW); // Turning off pin 4 (Trigger)
// Delay a set period of time (delay_seconds) to let the camera's flash recharge
delay(delay_seconds*1000);
}
}
//------------- Code Stops Here ----------------------------
7 posts - 2 participants