How to use laser sensor 40 m with Arduino

Hi everybody,

I bought a laser distance sensor 40 m.

I don't have a datasheet and I don't know how to communicate with Arduino.

The model is at this link:

https://it.aliexpress.com/item/40-m-precision-laser-distance-sensors-2mm-ranging-range-finder-module/32444067433.html?isOrigTitle=true

Can anyone help me please?

Thank in advance

Marco

It appears to be described under the header "apparente e l'interfaccia", but a translation to English would help.

Hi wvmarle,

thank you for your answer, it was helpful.

I have troubles still.

I don't know how to physically connect the sensor to Arduino.

Here the photos of what I received in the box of the product:

How to connect the cables to the sensors?

Thank you in advance

Marco

marcodepisapia:
Hi wvmarle,

thank you for your answer, it was helpful.

I have troubles still.

I don't know how to physically connect the sensor to Arduino.

Here the photos of what I received in the box of the product:

Dropbox - File Deleted - Simplify your life

How to connect the cables to the sensors?

Thank you in advance

Marco

From the Aliexpress page:

Module TXD >>> serial port RXD

Module RXD >>> serial port TXD

VCC >> 3.3V

Ground >> Ground

Then open serial monitor >> set baudrate 115200 and you will have output.

Hi Lennyz1988,

your answer is very clear.

My doubt was about the wire connection on the sensor.

I found an image of a similar sensor with indication of the connection:

The sensor is very similar to mine, so I think it will work. I hope so :slight_smile:

Thank you for your answer

Marco

Lennyz1988:
From the Aliexpress page:

Module TXD >>> serial port RXD

Module RXD >>> serial port TXD

VCC >> 3.3V

Ground >> Ground

Then open serial monitor >> set baudrate 115200 and you will have output.

Hi everybody,

I connected the laser sensor how specified above.
Then I used the following code, but NOT WRKING :frowning:

int byteInArrivo = 0;

void setup( ) {
Serial.begin(115200);
}

void loop( ) {
if (Serial.available( ) > 0) {
byteInArrivo = Serial.read( );
Serial.print("Ricevuto: ");
Serial.println(byteInArrivo, DEC);
}
}

How can I communicate with the laser sensor?

Thank you very much

Define "NOT WRKING".

Note that this is a 3.3V device. If you connected it to the serial port of a 5V Arduino, you may have destroyed it.

jremington:
Define "NOT WRKING".

Note that this is a 3.3V device. If you connected it to the serial port of a 5V Arduino, you may have destroyed it.

Hi jremington,

the sensor is OK, I connected to the 3.3V port, I know that it can be damaged by 5V port.
The code doesn't work properly because I can't read any value from the serial monitor. No communication.
Maybe a command to turn on the sensor is requested. I'm not an expert, I don't know.

What do you think?

Thank you

Marco

Maybe you need a level shifter in your serial lines; the sensor working at 3.3V means its serial lines will also be at that voltage when high. Maybe not high enough for your Arduino to detect?

On the flip side, your Arduino will be pushing 5V on those lines. That may be a problem for the sensor.

marcodepisapia:
Hi jremington,

the sensor is OK, I connected to the 3.3V port, I know that it can be damaged by 5V port.
The code doesn't work properly because I can't read any value from the serial monitor. No communication.
Maybe a command to turn on the sensor is requested. I'm not an expert, I don't know.

What do you think?

Thank you

Marco

This should be a manual for your sensor.

You definitely need a voltage divider on the RX pin of the module. You shouldn't need it at the TX pin.

The laser module may have been destroyed by connecting its 3.3 V RX to the Arduino 5V TX pin.

Lennyz1988:
This should be a manual for your sensor.
https://drive.google.com/drive/folders/0By24xk5Qp3qnZ1diZFVnWE1XYW8

You definitely need a voltage divider on the RX pin of the module. You shouldn't need it at the TX pin.

Hi Lennyz1988,

thank you for the manual, I found it very useful. I will try using a voltage divider. I will let you know.

Marco

Lennyz1988:
This should be a manual for your sensor.
https://drive.google.com/drive/folders/0By24xk5Qp3qnZ1diZFVnWE1XYW8

You definitely need a voltage divider on the RX pin of the module. You shouldn't need it at the TX pin.

Hi Lennyz1988,

I followed the instructions of your manual for the laser distance sensor.
I don't know how to send the instruction $00022123& to start the measurement.
I used the following code, but not working:

//-------------------------------------------------------------
int byteInArrivo = 0;

void setup( ) {
Serial.begin(115200);
}

void loop( ) {

Serial.write($00022123&); //start a single measurement
Serial.write($0003260130&); //turn on the laser light

if (Serial.available( ) > 0) {
byteInArrivo = Serial.read( );
Serial.println("Ricevuto: ");
Serial.println(byteInArrivo, DEC);

}

Serial.write($00022123&); //turn off the module

delay(1000);

}
//-------------------------------------------------------------------

It looks like the symbol $ gives an error.
How can I fix it?

Thank you in advance

Marco

The module expects character strings.

Instead of

Serial.write($00022123&);   //start a single measurement

Try

Serial.print("$00022123&");   //start a single measurement

You might also try with Serial.println

The instructions recommend use of a current limiting resistor, minimum 1K, for a 5V to 3.3 V input, but a voltage divider should certainly work.

There is an Arduino sketch in the link that I gave you.

(deleted)

Is the above comment a "useless answer", as a sign of a poor question?

That was a reply that for some reason ended up at the wrong thread.

Try this sketch, it works for me:

// LRF Arduino UNO
// VCC-----------VCC 2,8V
// RX------------TX pin3
// TX------------RX pin2
// GND-----------GND

// UKAZI
// "O" 0x4f PRIZGE laser, modul vrne "OK"
// "C" 0x43 UGASNE laser, modul vrne "OK"
// "S" 0x53 stanje modula, modul vrne temperaturo in napetost "18.0C, 2.7V"
// "D" 0x44 merjenje razdalje, modul vrne razdaljo in kvaliteto SQ "12.345m, 0079" Manjši SQ pomeni boljšo meritev

#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial LRF_Port (rxPin, txPin);

void setup()
{
Serial.begin(9600);
LRF_Port.begin(19200); // start serial communication between the LRF and Arduino
delay(100);
}

void loop()
{
LRF_Port.write("O"); // laser ON
delay(100);
Serial.print("prizgemo ");
Serial.print(LRF_Port.readStringUntil(13));
Serial.println();

LRF_Port.write("D"); // distance
delay(3000);
Serial.print("razdalja ");
Serial.print(LRF_Port.readStringUntil(13));
Serial.println();

LRF_Port.print("C"); // laser OFF
delay(100);
Serial.print("ugasnemo ");
Serial.print(LRF_Port.readStringUntil(13));
Serial.println();

LRF_Port.print("S"); // status
delay(100);
Serial.print("stanje ");
Serial.print(LRF_Port.readStringUntil(13));
Serial.println(); Serial.println();

delay(1000);
}

p.s.
sorry, I did not found button to attach sketch as code