I enjoy creating sumo robots and am constantly searching for innovative sensors and materials to improve the speed and intelligence of my robots. I discovered the RPLIDAR A1, available for $99 on DFROBOT.com. I mentioned my interest in testing the sensor, and they offered me the opportunity to test it out. Once I obtained the LIDAR, I discovered that it is too costly to be used in the upcoming competition I intend to participate in.
In this tutorial I’ll give you a basic understanding of how this sensor works and how you can use it with an arduino.
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 connection between the LIDAR and the Arduino’s hardware serial port (UART) must be established, which prevents the UART data from being sent to the serial console in a simple Arduino setup. Because they only have one Serial port. An additional software serial port can be added to improve basic Arduino models with only one hardware serial port. The library described in this manual does not yet offer assistance for a software serial port.
To debug and send serial data to the serial console, you will need an Arduino with multiple Serial ports. Examples include: Arduino Mega, Arduino M0 / Zero using SAMD21 chipset.
If there is no need to upload information for debugging purposes, you have the freedom to choose any Arduino board.
In this manual, I will showcase a more sophisticated version of Arduino – the Arduino M0 / Zero, which is equipped with the SAMD21 microcontroller.
Needed components:
- Arduino M0 ebay link
- Breadboard ebay link
- jumper wires ebay link
- 5V power supply ebay link
- 24 Led ring ebay link
- First you’ll need to install the RPLIDAR library from robopeak:
https://github.com/robopeak/rplidar_arduino, this library offers 2 interesting examples on how to use the LIDAR. You can find more information on how to install a library in the arduino IDE in this article: https://www.arduino.cc/en/Guide/Libraries - 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 task, we will attach a controllable LED ring to the LIDAR. In this manner, we are able to represent the LIDAR information graphically.
In this particular program, the LED will be activated towards the nearest detected signal.
Watch this video at the following link: https://youtu.be/L1iulgiau0E
The project’s code is derived from a sample provided by robopeak.
https://github.com/robopeak/rplidar_arduino/tree/m…
The changed code for this project is included in the zip file in this step.
Needed parts:
– LED ring: with 24 LEDS big enough to fit over the LIDAR, inner diameter 70mm
– Arduino Zero
– LIDAR
– Separate 5V power supply
– 3D printed part: https://www.thingiverse.com/thing:3185216
- Get all the needed parts
- Solder the wires to the LED ring
- Glue the LED ring to the 3d printed part
- Mount the 3D printed part onto the LIDAR, there are holes in the 3Dprinted part for M2.5 screws but I didn’t had them laying around to I just used hot glue
- Connect the wires from the LIDAR to the arduino:
GND -> GND
5V -> 5V of separate power supply
Di -> pin D5 of arduino - Upload the sketch and power up the external power supply
Final result can be viewed here on youtube:
Source: How to Use the RPLIDAR 360° Laser Scanner With Arduino