Can anybody help me with my code to get my lidar lite v3 to flash led at different rates/ frequencies as the distance decreases.I am in need of help because the project deadline is soon aproching and I would be ever so greatful if someone would give me a hand
sorry Im only 14 and new to arduino software and Im just trying to programe the sensor to flash an LED more rapidly as distance decreases but i am not having much sucsess while doing so. I would be greatful if you (PaulS) could put me on the path regards to making my code work
Just finished my first working prototype . If you have any suggestions please leave a reply
unsigned long pulseWidth;
void setup()
{
Serial.begin(115200); // Start serial communications
pinMode(2, OUTPUT); // Set pin 2 as trigger pin
digitalWrite(2, LOW); // Set trigger LOW for continuous read
pinMode(3, INPUT); // Set pin 3 as monitor pin
pinMode(13, OUTPUT);
}
void loop()
{
pulseWidth = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds
pulseWidth = pulseWidth / 10;
// If we get a reading that isn't zero, let's print it
if(pulseWidth >= 51 && pulseWidth <= 100)
{
// 10usec = 1 cm of distance
Serial.println(pulseWidth); // Print the distance
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
else if(pulseWidth >= 10 && pulseWidth <= 50)
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(50);
}
}
// Setup software serial port
SoftwareSerial mySerialone(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
SoftwareSerial mySerialtwo(15,14); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini1;
TFMini tfmini2;
void setup() {
// Step 1: Initialize hardware serial port (serial debug port)
Serial.begin(9600);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);
Serial.println ("Initializing...");
}
void loop() {
// Take one TF Mini distance measurement
mySerialone.begin(115200);
tfmini1.begin(&mySerialone);
uint16_t dist1 = tfmini1.getDistance();
uint16_t strength1 = tfmini1.getRecentSignalStrength();
// Display the measurement
Serial.print(dist1);
Serial.print(" cm sigstr: ");
Serial.println(strength1);
mySerialone.end();
delay(500);
// Take one TF Mini distance measurement
mySerialtwo.begin(115200);
tfmini2.begin(&mySerialtwo);
uint16_t dist2 = tfmini2.getDistance();
uint16_t strength2 = tfmini2.getRecentSignalStrength();
// Display the measurement
Serial.print(dist2);
Serial.print(" cm sigstr: ");
Serial.println(strength2);
mySerialtwo.end();
// Wait some short time before taking the next measurement
delay(500);
if (dist1<100 || dist2<100)
{
Serial.println("**************************************************");
NewTone(3,50,100);
}
}
Hello I am facing problem when connecting 2 TF mini lidar to arduino mega 2560
First thing you need to do is explain why you are using two instances of the SoftwareSerial class, while ignoring three hardware serial ports on the Mega.
void loop() {
// Take one TF Mini distance measurement
mySerialone.begin(115200);
tfmini1.begin(&mySerialone);
uint16_t dist1 = tfmini1.getDistance();
Second thing you need to do is explain what you were smoking when you decided that SoftwareSerial could work reliably at that baud rate.
Third thing you need to do is explain why you are calling the two begin() methods on EVERY pass through loop(). The begin() methods should be called in setup(), NOT loop().
mySerialone.end();
Fourth thing you need to do is explain why you ever call end(), let alone on every pass through loop().