So for today’s project, we will make a LiDAR-based security system that can carry out a 360-degree scan of its surroundings as well as sense up to 8 -10 metres or more (depending on the LiDAR type and model). And the best part is that you can obtain a real-time distance of moving objects on radar.
Suppose a person/vehicle is approaching a restricted area and you want to stop them. Using this LiDAR-based security system, one can do so by scanning their current location and obtaining their point of origin – all in real-time.
Bill of material
First, purchase the following components:
After getting these components, install the YDLIDAR SDK and relevant Python modules to run the Python code and visualise the live data of the scanned environment.
To begin, clone the LIDAR SDK in the Linux terminal using the following command:
git clone https://github.com/YDLIDAR/YDLidar-SDK
sudo make install
Next, install the YDLIDAR Python library
python3 setup.py build
python3 setup.py install
Now install NumPy and matplot libraries
sudo pip3 install matplotlib
sudo pip3 install numpy
Since the Python code is in the YDLIDAR Python folder, enter it and open the plot_ydlidar.py file in the Python 3 IDLE. To run the code for scanning the environment, make some modifications.
Firstly, change the port name to the LiDAR port name (here it’s “/ttyUSB0”…yours can be different).
Next, change the LiDAR baud rate for serial communication. Here we are using the X2L model of LiDAR whose baud rate is 115200.
After this, set the PropSingleChannel to True.
Now our code is ready to run.
Power the LiDAR by connecting it to Raspberry Pi’s USB port and run the code to get real-time data of the scan. It shows the path of an object between two distant points in the LiDAR range. It also displays the movement points at any angle. By placing the computer mouse cursor on any of the points, one can know the accurate distance/angle of that object from LiDAR.