For my project I am trying to build an app that will receive data from my sensor. I am using a TFmini lidar sensor, an ardiuno mega 2560, an HC-05 bluetooth module, and Mit app inventor.
This is basically what im trying to accomplish:
Sensor -> Arduino -> Bluetooth -> App
In this project, I'm using a lidar sensor to measure the distance between the sensor and an incoming object as well as it's speed. The sensor is stationary and an object will be approaching it around 10kph. When the sensor sends the distance and speed values, I want to display those values on my app.
I've successfully connected the HC-05 with my app (that was the easy part). I've also changed the baud rate of the HC-05 to 115200. My problem is that my app won't display the sensor values. The serial monitor on the arduino program displays all the values I need. I don't know if my problem is in my code or in the in app inventor blocks.
Below is my code:
#include <DFRobot_TFmini.h>
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
Serial.print("Data|");
Serial.print(distance);
Serial.print("|");
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
Serial.print(distance);
Serial.print("|");
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
Serial.print(distance);
Serial.print("|");
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
Serial.print(distance);
Serial.print("|");
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("|");
distance5 = distance;
velo4 = ((distance4 - distance5) / (0.1))*0.036;
velo = (velo1 + velo2 + velo3 + velo4) / 4;
Serial.println(velo);
delay(50);
}
delay(50);
}
I've also attached a screenshot of the serial monitor and the blocks from my app.
Any help will be greatly appreciated!!!!