How to Use the RPLIDAR 360° Laser Scanner With Arduino

About: Hello, I'm Bruce. I'm a student in Belgium. I have a wide variety of interests: electronics, computers, technology, ... In my spare time I spend a lot of time on: projects, exploring the internet, cycling. ...
More About geo bruce »

I'm a big fan of building sumo robots and I'm always on the look for new interesting sensors and materials to use to build a better, faster, smarter robot. I found out about the RPLIDAR A1 which you can get for $99 at DFROBOT.com . I said I was interested in trying out this sensor and they gave me the chance to try one. After I got the LIDAR I found out I was not allowed to use this type of sensor in the competition I'm planning to attend because it's too expensive.

In this tutorial I'll give you a basic understanding of how this sensor works and how you can use it with an arduino.

Supplies:

Step 1: LIDAR What?

Wikipedia had two different meanings for LIDAR:- LIght Detection And Ranging- Laser Imaging Detection And Ranging

In general it can be seen as a distance sensor on a rotating base, which samples range data while continuously rotating. For each successful sample the measured distance is sent with the according angle.In this case the data is sent over UART.

Step 2: Using an Arduino to Interface With the LIDAR

The LIDAR needs to be connected to the hardware serial port (UART) of the Arduino, for an basic arduino this means you can't send any UART data to the serial console. Because they have only one Serial port. For basic Arduino's with only 1 hardware serial port, you can add an extra software serial port. The library that'll be used in this instructable doesn't support a software serial port (at the moment of writing).

So if you want to be able to send send serial data to the serial console for debugging purposes you'll need an arduino with more than one Serial port. Like there are: Arduino Mega, Arduino M0 / Zero (SAMD21).If you don't need to send data to the computer to debug you can pick any arduino.

For this instructable I'll be using a more modern and more powerful arduino based on the SAMD21 microcontroller, The Arduino M0 / Zero.

Now open the "simple_connect" example code that is included in the library.

Make the necessary hardware connections from the LIDAR to the arduino:- Connect the RPLIDAR's serial port (RX/TX/GND) to your Arduino board (Pin 0 and Pin1)

- Connect the RPLIDAR's motor ctrl pin to the Arduino board pin 3- Use an external 5V power supply to power the motor control pin and the LIDAR.

In the void setup you'll have to change following code: "lidar.begin(Serial);" according to the used serial port. When using an Arduino M0 you should change "Serial" to "Serial1". This can be different for other Arduino's.

The first picture is what the example sketch should look like, lines 60-63 contain the variable names which you can use to get the data from the LIDAR.

If you want to know what this data looks like you can print this data to the serial monitor, with the code in the second picture.

In the following step we'll make a very basic working project with the LIDAR and a LED ring.

Step 3: Making the LIDAR LED Ring Project

For this project we will mount an addressable led ring onto the LIDAR. This way we can visualize the LIDAR data.In this specific program the LED will be turned on in the direction of the closest detected signal.

The code for this project is based on one of the examples from robopeak: