# How to use laser sensor 40 m with Arduino

**URL:** <https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389>\
**Category:** Sensors\
**Created:** [June 12, 2017, 5:09pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389 "2017-06-12T17:09:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 12, 2017, 5:09pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/1 "2017-06-12T17:09:31Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [June 13, 2017, 3:20am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/2 "2017-06-13T03:20:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 14, 2017, 1:56pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/3 "2017-06-14T13:56:19Z")

</div>

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](https://www.dropbox.com/sh/7eb1zdcky27ftu7/AACehqi6Ie8z-rG5FAQIVQ0fa?dl=0)**
>
> Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!

How to connect the cables to the sensors?

Thank you in advance

Marco

---

<div class="post-metadata">

**Author:** ![Lennyz1988](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lennyz1988](https://forum.arduino.cc/u/Lennyz1988)\
**Post date:** [June 14, 2017, 3:11pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/4 "2017-06-14T15:11:17Z")

</div>

> 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](https://www.dropbox.com/sh/7eb1zdcky27ftu7/AACehqi6Ie8z-rG5FAQIVQ0fa?dl=0)
> 
> 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.

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 15, 2017, 2:47pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/5 "2017-06-15T14:47:56Z")

</div>

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:

> **[This product is no longer available.](https://www.alibaba.com/product-detail/laser-distance-sensor-module_60292736822.html)**
>
> This product is no longer available.

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

Thank you for your answer

Marco

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 20, 2017, 9:33am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/6 "2017-06-20T09:33:54Z")

</div>

> 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 ☹

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 20, 2017, 2:36pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/7 "2017-06-20T14:36:03Z")

</div>

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.**

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 21, 2017, 9:49am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/8 "2017-06-21T09:49:16Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [June 21, 2017, 12:15pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/9 "2017-06-21T12:15:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lennyz1988](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lennyz1988](https://forum.arduino.cc/u/Lennyz1988)\
**Post date:** [June 21, 2017, 1:09pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/10 "2017-06-21T13:09:04Z")

</div>

> 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.

> **[Google Drive: Sign-in](https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F0By24xk5Qp3qnZ1diZFVnWE1XYW8&followup=https%3A%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F0By24xk5Qp3qnZ1diZFVnWE1XYW8&ifkv=ATuJsjxh8gkXvwMne3lg6xXr45iFk5UiigYBl7vhIk5yr-t5OdkhXaDJui31OUj7ZuB95nJncjlx&osid=1&passive=1209600&service=wise&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S-2045878365%3A1708932905089538&theme=mn)**
>
> Access Google Drive with a Google account (for personal use) or Google Workspace account (for business use).

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 21, 2017, 4:01pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/11 "2017-06-21T16:01:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 22, 2017, 10:03am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/12 "2017-06-22T10:03:19Z")

</div>

> Lennyz1988:  
> This should be a manual for your sensor.  
> [https://drive.google.com/drive/folders/0By24xk5Qp3qnZ1diZFVnWE1XYW8](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

---

<div class="post-metadata">

**Author:** ![marcodepisapia](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marcodepisapia](https://forum.arduino.cc/u/marcodepisapia)\
**Post date:** [June 27, 2017, 2:46pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/13 "2017-06-27T14:46:45Z")

</div>

> Lennyz1988:  
> This should be a manual for your sensor.  
> [https://drive.google.com/drive/folders/0By24xk5Qp3qnZ1diZFVnWE1XYW8](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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 27, 2017, 3:11pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/14 "2017-06-27T15:11:18Z")

</div>

The module expects character strings.

Instead of

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

```

Try

```cpp
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.

---

<div class="post-metadata">

**Author:** ![Lennyz1988](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lennyz1988](https://forum.arduino.cc/u/Lennyz1988)\
**Post date:** [June 27, 2017, 4:56pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/15 "2017-06-27T16:56:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [June 27, 2017, 5:17pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/16 "2017-06-27T17:17:25Z")

</div>

(deleted)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 28, 2017, 3:23am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/17 "2017-06-28T03:23:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [June 28, 2017, 3:36am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/18 "2017-06-28T03:36:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrej](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@andrej](https://forum.arduino.cc/u/andrej)\
**Post date:** [August 20, 2017, 7:12pm UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/19 "2017-08-20T19:12:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:17am UTC](https://forum.arduino.cc/t/how-to-use-laser-sensor-40-m-with-arduino/464389/20 "2021-05-06T10:17:54Z")

</div>

Closed on May 6, 2021, 10:17am UTC


