Capture incoming people or vehicles with the Raspberry Pi and LIDAR

David - Touch4IT
Dávid Ondruš
Mar 30, 2020
3 min read
raspberry pi

A motion sensor and a camera attached to the Raspberry Pi connected to the Internet and you can have a database of people coming into a building, licence plates of cars entering a garage, etc.

Motion detection

The LIDAR sensor wasn’t my first choice when I was looking for a suitable distance sensor. Ultrasonic sensors came to mind first but they were making my solution unusable in some circumstances. Sensors like HC-SR04 (often used with Arduino) are small, simple and cheap, but suitable only for smaller distances and they can’t fulfil the project’s requirement of detecting objects 6–10 meters away. Outdoor weather resistant sensors like MB7092 XL-MaxSonar-WRMA1 were good enough in the detection of regular objects with surfaces like glass, wood or steel but were failing to detect persons wearing various types of clothes. Also, in larger distances, people weren’t detected at all because of too wide pulse range. GARMIN’s LIDAR-Lite v3 sensor (optical with laser) solved all my problems with precise motion detection in large distances, but was also the most expensive from all the ones I’ve tried.

garmin lidar-lite v3
Source: buy.garmin.com

How to select only incoming objects?

Since my use case required handling only specific situations, I had to implement an algorithm to distinguish between incoming objects (getting closer to the sensor) and objects leaving the area. Python script reads values from the sensor with a frequency of 20 Hz and for better accuracy it averages a few values in a row to minimize the chance of false positives. Averaged values are then compared and their increase or decrease is evaluated. A greater value means larger distance, which means an object getting far away. A lower value means smaller distance so an object is coming closer. After the analysis of few real situations I’ve set a minimum difference between values, which must be met to even take that value into consideration.

Capture the object

The motion sensor serves as a trigger for the camera, taking a photo immediately on command from the motion sensor. The script uploads a photo asynchronously so no additional detection is missed because of a delay.

raspberry pi
Source: raspberrypi.com

Configurability

Every numeric variable in the script is configurable via the user interface, provided by the backend application running on a remote server. Minimum and maximum distances, frequency, number of values to average, camera resolution and other variables can be adjusted remotely for the needs of every place where this solution will be used. Thus, for example, places with low quality internet connection can use a smaller camera resolution to speed up the uploading of a photo.

The cost of hardware and are there another options?

The hardware components cost around 200 EUR, which is higher than I expected for this project. That is mainly because of the higher price tag of the LIDAR sensor, but a few cheaper LIDAR sensors exist on the market. Just test one piece thoroughly before ordering more to be sure the model fits the use case. Also, the most expensive Raspberry Pi 4 configuration (4GB RAM) was used so the price can be reduced using a cheaper variant. The Camera Module v2 was used as the only one recommended and official option for Raspberry Pi.

TL;DR

Using the Raspberry Pi, LIDAR sensor and Camera Module I’ve been able to build a compact and portable hardware solution for detecting incoming objects such as people and vehicles, taking a photo of them and uploading to a remote server. Rich configurability ensures its usability in various types of places from small offices to long tunnels. It may sound like a trivial solution but this project solved real world issue for the client in the MVP phase. With my team at Touch4IT, we prefer to test the MVP first so it’s cheaper and faster for our customer, then iteratively improve the solution for final production use.

Do you want to develop something you have no experience with? Don’t have an innovation department or people? We would be more than happy to have a talk with you and find the right solution.