Hello there.
For my project I am using a mega 2560, a tf mini lidar sensor, and an HC-05 bluetooth module.
I'm trying to calculate distance and speed of an incoming object using the tf mini and then outputting, with the help of the HC-05 module, the values on a app that I made using MIT App inventor.
My problem is that when I connect the HC-05 to the system, the tf mini starts outputting the value 6553. When I connect the tf mini and disconnect the HC-05, and monitor the serial monitor I get the proper distance and speed values.
Any advice would be highly appreciated!!
My code:
#include <DFRobot_TFmini.h> //TF mini library
SoftwareSerial mySerial(12, 13); // RX, TX
DFRobot_TFmini TFmini;
uint16_t distance,strength;
long distance1,distance2,distance3,distance4,distance5,velo,velo1,velo2,velo3,velo4;
void setup(){
Serial.begin(115200);
TFmini.begin(mySerial);
}
void loop(){
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
distance1 = distance;
delay(50);
}
delay(50);
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
distance2 = distance;
velo1 = ((distance1 - distance2) / (0.1))*0.036;
delay(100);
}
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
distance3 = distance;
velo2 = ((distance2 - distance3) / (0.1))*0.036;
delay(100);
}
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
distance4 = distance;
velo3 = ((distance3 - distance4) / (0.1))*0.036;
delay(100);
}
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
Serial.print(distance);
Serial.print(" cm");
Serial.print("|");
distance5 = distance;
velo4 = ((distance4 - distance5) / (0.1))*0.036;
velo = (velo1 + velo2 + velo3 + velo4) / 4;
Serial.print(velo);
Serial.print(" kph");
Serial.print("|");
delay(100);
}
delay(50);
}