Arduino Projects

What is Lidar? Lidar Working, TF Mini Lidar with Arduino Connection & Code

Lidar (Light detection and ranging)

LIDAR is the abbreviation of the term Light Detection and Ranging. Lidar is a remote sensing method that uses laser to measure elevation like ground forest and buildings. The light energy emitted by Lidar is known as pulse. Light reflected from ground or object is known as return. This means the Lidar system sends a pulse of light and it wait for the pulse to return and measures how long it take the emitted pulse to return back  to the sensor, in the end it gets variable distance of the objects actually this is how Lidar got its name Light detection and ranging . Lidar uses ultraviolet visible or near infrared source objects to sense objects. As the laser light is reflected from the object it is detected by the sensor.

Lidar

Like a sonar used sound wave, radar uses radio waves similarly Lidar on the other hand uses light sent out from a laser a Lidar unit scan the ground from side to side as the plane flies because of this it covers the larger whole some pulses will be directly at nadir or a straight line most pulses travel at an angle.

Airplanes unmanned aerial vehicles and helicopters most commonly used platform for acquiring Lidar data over broad areas. There are different ways to collect data using lidar from ground from plane or from satellite


 three types of Lidar

Topographic Lidar

It maps the land using near infrared light.

Metric Lidar:-

 It uses water penetrating green light to measure seafloor and river bed elevation.

Terrestrial Lidar:-

It is used for mapping buildings natural features and tree at ground it is also very useful for 3d model of heritage sites.

Lidar

 LIDAR Working:-

The working of lidar operation is simple. The dedicated light beam is pointed at an object and the sensor looks for its reflection. If the beam is detected its intensity and phase is measured. The values are then plugged into an equation run by a fast onboard computer to control the reflecting objects position and features by sweeping the beam and the receiver array mechanically we can quickly build up a 3d image of the surrounding area Which is often showed in a point cloud to help us individuals visualize what the lidar is seeing.

Obviously lidar is not the only method that can be used to sense external surroundings.

The LIDAR system works on the time of flight principle where laser in pulsed form is targeted onto the object and the reflected or scattered pulse is measured using the detector. From measuring the time difference b/w the transmitted and reflected pulse. The distance between the objects can be calculated.  As laser beam has less expansion with travel distance and it has very short wavelength it can also be used for scanning of the object mapping and surface scanning applications.

Difference between LIDAR and Ultrasonic Sensors

The HCSR04 devices are low cost and easy to use components that take up about the same amount of space as the motionless lidar sensor. They also use about the same amount of current.

The HCSR04 sensors work on basically the same principle as our lidar sensors except. They use ultrasonic sound in place of infrared light. It have a range from about 2 cm to 4m so they can cover items at closer range than lidar but not as far.

The HCSR04 sound is not as directional as light so an ultrasonic sensor cannot be used to create a point cloud. The sound travels much slower than the light you are limited to how much data you can gather in a short period of time and not all objects reflect ultrasonic sound. Some items absorb sound and does not reflect enough of it back to get a good reading and HCSR04 sensors have a lot of good points in their favor. They are much cheaper than lidar can detect objects reasonably close and easy to use.



Difference between LIDAR and IR Light Sensor

The IR LED and the receiver diode used for collision detection applications assemblies output a pulse when they detect an object at or closer than a preset distance. We can adjust the distance they trigger at using an onboard potentiometer. The devices are inexpensive and as they also work using IR light beams they are very fast. They have a range that extends from just a few millimeters to about 10 cm so they work at a much closer range than lidar does.

These modest IR light sensors do not provide any data on the quality of the returned light or an actual distance measurement. They are best used as alarm type sensors that trigger when an outside object is detected at a preset range. Countless to send an interrupt to tell your robot that it is about to hit an object.

Difference between LIDAR and RADAR

The lidar is based upon the same standard as radar except it makes use of light beams instead of high frequency radio waves.

A developed radar array is not that practical for a small robot project however small microwave and the radar sensors are available. It can be used in similar applications as lidar and have similar or greater ranges and capabilities. Few items absorb or pass radio waves and are not detected well using radar.

A radar is based upon microwaves it is as speedy as lidar. The lidar does have a benefit in resolution but radar is still pretty skilled.  The low power levels required for a small sensor radar would not pose a threat to human or animal health but will consume a bit more current than lidar sensors.The Radar uses radio waves (Longer Wavelength) but LIDAR uses Light waves (Shorter Wavelength).

The Lidar is more accurate than the radar as it uses shorter wavelength. The radar can work in harsh environments like fog rain and snow while Lidar has limited usability in such environments. It is used in applications where detection distance is important but it is not the exact size and shape of an object like in military applications. The lidar is used in applications where the detection of exact shape and size of the object is necessary The Self driving vehicles use a combination of lidar and radar sensors. We can see there are benefits and hindrances of all types of sensors including lidar. In a difficult robot project you would probable use most if not all of the above technologies.

Amazon Purchase Links:

Arduino Uno

Arduino Nano

Lidar

Logic Level Converter

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Components of LIDAR

LASER

The most of the laser that are used in the lidar are in the range near infrared but in some applications like in underwater applications even green lasers are also used.

DETECTOR

The second component of Lidar is called detector which is used in circuit to measure the reflected or the scattered light which is coming from the object.


OPTICS and Rotating mechanism

The 3rd component of this Lidar system is the optics and the rotating mechanism to scan the object.

Timing Electronics

It is used to measure the difference between the transmitted pulse and received pulse

Computer

This lidar system used to generate the enormous amount of data points in real time so to compute that data we also require the computer

GPS and IMU

GPS and IMU which stands for the inertial moment unit are also part of this lidar system.

GPS receiver track the altitude and orientation of the lidar these variable are important in attaining terrain elevation values. IMU track the speed and orientation of the lidar to accurately determine the actual position 0n the ground.

Lidar

TF mini Lidar (Laser Range Sensor):-

The TF mini lidar is a single laser range finder based upon time of flight technology which consists of exceptional optical and electronic devices which integrates adaptive algorithm for indoor and outdoor application atmosphere. It contain small body and high performance in distance measurement.

Lidar

Lidar

Lidar

the laser sensor can be used as a distance measuring tool to detect the distance from it to hindrances. It can also be used as an eye of a robot. It delivers distance info for robotic safe escaping and route selection. It supports for system automation in a variety of machine control scenarios. Due to its small size light weight and low power consumption it is also suitable for altitude hold quad copters and terrain following

Lidar


TF mini Lidar features

  1. It is single directional laser range finder
  2. It Maximum Detection Range: 12m
  3. It Perform excellent in distance measurement, high precision.
  4. It Support 100Hz sampling resolution, responsive.
  5. The Small size and low power consumption.

TF mini Lidar applications

  1. Machine control and safety measurement systems
  2. Laser range finder robot
  3. Altitude hold quad-copters and terrain following

TF mini Lidar specification

  1. Voltage Range: 5V±0.1V
  2. Communication Interface: UART / I2C
  3. Working Range: 0.1m-12m @90% Reflectivity
  4. Average Power: 0.6W
  5. Acceptance Angle: 2°
  6. Minimum Resolution: 1mm
  7. Refresh Frequency: 100Hz
  8. Ranging Accuracy: ±6cm@ (0.1-6m) ±1%@ (6m-12m)
  9. Ranging Unit: mm
  10. Band: 850nm
  11. Size: 1.65in x0.59in x0.63in / 42mm x15mm x16mm
  12. Operating Temperature: 0°C ~ 60°C
  13. Storage Temperature: -20°C~75°C
  14. Anti-light Environment: 70Klux
  15. Weight: 4.7g

Connection of TF Mini LIDAR with Arduino

5V Arduino w/ Atmega328P Logic Level Converter (High Side) Logic Level Converter (Low Side) TFMini
Software Serial RX
(Pin 10)
HV1 LV1 UART_TX (3.3V TTL)
(Pin 1)
Software Serial TX
(Pin 11)
HV4 LV4 UART_RX (3.3V TTL)
(Pin 2)
3.3V LV
5V HV Vin (4.5V-6V)
(Pin 3)
GND GND GND GND
(Pin 4)


The Connection of the TF Mini LIDAR unit to the Arduino:

Lidar

Here the logic level converter uses both a 5 volt and 3.3 volt power supply both are taken from the Arduino Uno.

The pin 10 connection of the Arduino is used as a receive pin for the data from the TX output of the TF Mini lidar. That the data runs through channel A of the convertor. The Pin 11 of the Arduino is used as a transmit pin for data sent to the RX input on the TF Mini. It runs through channel B of the convertor protecting the RX input from the 5 volt logic used in the Arduino.

The chart on the Connection diagram should assist you in making the correct connections.

TF Mini LIDAR Arduino Sketch

After Connection let us run a sketch to determine the abilities of the TF Mini lidar unit.

We are going to take install a library for the TF Mini lidar into our Arduino ide and then run a sample sketch included with the library.

  • Open the Arduino ide
  • Go to the Sketchmenu then highlight Include Library.
  • SelectManage Libraries from the displayed sub menu.
  • The Library Manager will open in its own window.
  • In theFilter Your Search box type “tfmini”
  • The result should be the TF Mini Library by Peter Jansen.
  • Click the More Info An Install button will appear.
  • Click the Installbutton to install the library into your Arduino IDE.
  • You may now close the Library Manager.

Another library will be used with our demo sketch as well this one is already installed by default into your Arduino IDE.  It is the Software Serial Library and it resolves a problem you will encounter using more than one serial device with your Arduino.

Your Arduino Uno has a single Hardware Serial port an input (RX) on pin 0 and an output (TX) on pin 1. Inside these two pins are used in the USB interface that connects your Arduino to your computer.

As Uno only has one serial port you will run into problems using a device like the TF Mini lidar which itself requires a serial port. If you use pins 0 and 1 you would not be able to use the Serial Monitor on the USB port which creates a problem as that is exactly what we want to do here.

The Software Serial Library provides the solution. It allows you to use any two pins on an Arduino Uno as serial I/O pins and it handles the serial encoding and decoding of the data.

It is not perfect and it will not perform as well as a hardware serial port but it will certainly work with our sketch.

The sketch itself is included with the TF Mini Library.

  • To use it open the File menu and select Examples.
  • Scroll down the list of examples to the section labeled “Examples from Other Libraries”.
  • Look for TF Mini and expand it.
  • You will see two example sketches.

One example is called Single Reading. This is actually a “skeleton sketch”, by itself it does not accomplish much but it is full of comments to where you would add your own code. You can use this as the basis for a design based upon the TF Mini.

The example we will be using is the other one Basic Reading. Name suggesting it takes basic readings from the TF Mini LIDAR sensor and displays the results on the serial monitor.

The sketch starts by loading the TF Mini and Software Serial libraries.  After that the Software Serial port is setup as an object called “my Serial” using pins 10 and 11 as receive and transmit respectively.

An object called “tfmini” is also created using the TF Mini library.

In arrangement the hardware (USB) serial port is setup.  Remember this is set to a speed of 115,200 bps which is possibly faster than your Arduino ide serial monitor is currently setup. When you first run the sketch you will need to alternate the speed on the serial monitor to match.

This Software Serial setup is next. The constant it uses for baud rate is derived from the TF Mini library. The final step in the setup is to initialize the TF Mini sensor itself.

The loop things are actually simple. The couple of 16 bit integers are defined and the assigned to the value of the Tf Mini distance and signal strength readings.  Then these values are displayed on the serial monitor. When that is done a brief delay is set and the loop begins again.

TF Mini lidar with Arduino Testing

After loaded everything and connecting up open your Serial Monitor in the arduino ide. If you are meet with a bunch of error make sure that the baud rate is set to 115,200 bps this can be adjusted using the dropdown box on the bottom of the serial monitor. You may need to reset the Arduino after changing baud rate.

As you get the serial monitor working you should be greeted by a display of distance and signal strength. Now Pick up the TF Mini LIDAR sensor and point it at a distant object while observing these readings.

Recall that the TF Mini LIDAR sensor has a minimum range of 30 cm  which is about a foot. Any objects closer than that will register as being at 30 cm.

Though this is a simple sketch it does illustrate how informal it is to work with the TF Mini lidar sensor. One thing you will note is how quickly you get data back specifically if you associate it to the experiments we did using the HCSR04 Ultrasonic Sensor. It shows how quickly a light based position sensing system is compared to one based upon sound.



TF Mini Lidar Arduino Programming

/*

     This example communicates to the TF Mini using a Software Serial port at 115200,

While communicating the distance results through the default Arduino hardware

Serial debug port

Software Serial for some boards can be unreliable at high speeds (such as 115200).

The driver includes some limited error detection and automatic retries, that

Means it can generally work with Software Serial on (for example) an UNO without

The end-user noticing many communications glitches, as long as a constant refresh

Rate is not required.

The (Uno) circuit:

 * Uno Rx is digital pin 10 (connect to TX of Tf mini)

 * Uno TX is digital pin 11 (connect to Rx of Tf mini)

This software is provided ”as is” and any

Express or implied warranties, including, but not limited to, the implied

Warranties of merchantability and fitness for a particular purpose are

Disclaimed. In no event shall the author(s) be liable for any

Direct, indirect, incidental, special, exemplary, or consequential damages

(Including, but not limited to, procurement of substitute goods or services;

Loss of use, data, or profits; or business interruption) however caused and

On any theory of liability, whether in contract, strict liability, or tort

(Including negligence or otherwise) arising in any way out of the use of this

Software, even if advised of the possibility of such damage.

*/

#include < Software Serial .h>
#include "TF Mini .h"

// Setup software serial port 
Software Serial my Serial (10, 11);      // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TF Mini Tf mini;

Void setup () {
  // Step 1: Initialize hardware serial port (serial debug port)
  Serial. Begin (115200);
  // wait for serial port to connect. Needed for native USB port only
  While (! Serial);
     
  Serial. Print ln ("Initializing...");

  // Step 2: Initialize the data rate for the Software Serial port
  My Serial. Begin (TFMINI_BAUDRATE);

  // Step 3: Initialize the TF Mini sensor
  Tf mini .begin(&my Serial);    
}


Void loop () {
  // Take one TF Mini distance measurement
  Uint16_t dist. = Tf mini. Get Distance ();
  Uint16_t strength = Tf mini. Get Recent Signal Strength ();

  // Display the measurement
  Serial. Print (dist.);
  Serial. Print (" cm      sigstr : ");
  Serial. Print ln (strength);

  // Wait some short time before taking the next measurement
  Delay (25);  
}


Applications of LIDAR

  1. Agriculture
  2. Police Trafficking
  3. Autonomous Vehicles
  4. Video Games
  5. Soil Research
  6. Flood mapping of River
  7. Military
  8. Study of Atmosphere
  9. Self-directed vehicles
  10. Survey
  11. Pollution Modelling
  12. Building Construction

Agriculture:- 

The lidar can be used to create 3d elevation map of a particular land.  It can be converted to create slope and sunlight exposure area map. The information can be used to identify the areas which require more water or fertilizer and this help farmers to save on their cost of labor time and money.

 Survey:- 

The water penetrating green light of the lidar can be used to see things underwater and it helps create a 3d model of the terrain. The underwater information of a river can help understand the depth width and flow of the water. Which helps in monitoring the floodplains.

Pollution Modelling:-

The lidar wavelength is shorter. Lidar operates in ultraviolet visible region or near infrared. This helps to image the matter which is of the same size or larger than the wavelength. So the lidar can detect pollutant particles of carbon dioxide and methane. The info helps academics to create impurity density map of the area which can be used for better planning of the city.

Building Construction 

The lidar plays an important role for the archeologist to understand the surface. The lidar can detect micro topography that is hidden by vegetation which helps archeologist to understand the surface.

Self-directed vehicles

The lidar works as an eye of the autonomous vehicle.  If your eyes allowed you to see in all directions all the time instead of predicting you could always know the exact distance of objects in relation to you. The lidar enable an Autonomous car to view the surroundings with special powers. The ground based lidar technology can be used to capture the structure of the building. This digital information can be used for 3d mapping on the ground which can be used to create models of the structure.  And it is very useful for maintaining a record of the structure.

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button