This is another illustration that demonstrate how to wire the LIDAR Sensor on your Microcontroller. LIDAR (Light Detection and Ranging) is a remote sensing device which is capable capture geographical information. LIDAR data is often collected by the survey of aircraft or ground vehicle. NOAA scientist use LIDAR devices to examine both natural and man-made environment. LIDAR Data supports activities such as inundation, storm surge modeling, hydrodynamic modeling, shoreline mapping, emergency response, hydro-graphic surveying, coastal vulnerability analysis. LIDAR also use in self-driving cars and advance robotics.
Block Diagram
- Power : 4.7 ~ 5.5 DC Nominal, Maximum 6V DC
- Current Consumption <2mA @ 1 Hz (Shutdown between measurements), < 100mA (Continuous Operation)
- Max Operating Temp: 70 Degree Celsius
- External Trigger 3.3v Logic, HIGH/LOW Triggered
- PWM Range Output: PWM Signal proportional Range, 1 msec/meter, 10 usec step size
- i2c Machine Interface: 100Kb – Fixed, 0xC4 slave address. Internal register access and control.
- Support i2C Command: Single distance measurement, velocity, signal strength
- Mode Control: Busy Status i2C, External Trigger Input / PWM Output
- Max Range Under Typical Conditions: ~ 40m
- Accuracy: +/-2.5cm, +/- ~1″
- Default Rep Rate: ~50 Hz
On illustration we are going to wire the LIDAR-Lite by pulsedlight3d & Garmin a low cost LIDAR that can be used in Automotive Blind-spot sensing, traffic monitoring, 3D image scanning, collision avoidance, industrial level measurement, security system components, medical imaging, aerospace. The LIDAR-Lite is using i2C serial communication bus, easily to communicate with your SBMC (Single Board Micro Computer) or in your MCU (Microcontroller). LIDAR-Lite can be connected as slave under the control of the master i2c. It supports standard 100 kHz data transfer mode, and it has 7bit slave address with a default value of 0x62 HEX notation. The effective 8bit address is OxC4 write, OxC5 read. Please refer the official datasheet can be download below.
Required Components
- Arduino Microcontroller, Teensy (Teensy Duino), ATMEGA328 16/12, ATMEGA32u4 16/8/ MHz, ESP8266, ATMEGA250 16 MHz, ATSAM3x8E, ATSAM21D, ATTINY85 16/8 MHz (Note: The Diagram below is using NANO. If your using other MCU please refer to the respective pin-outs diagram)
- LIDAR – V1 / LIDAR – V2 / LIDAR – V3
- Capacitor (680UF)
- Resistor (1K)
- Jumper Wire / DuPont Wire
- Solder Less Bread Board
i2C Wiring Guide
PWM / Continuous Mode Wiring Diagram
i2C Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* You can find more information about installing libraries here: http://arduino.cc/en/Guide/Libraries */ #include <I2C.h> #define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite. #define RegisterMeasure 0x00 // Register to write to initiate ranging. #define MeasureValue 0x04 // Value to initiate ranging. #define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call. void setup(){ Serial.begin(9600); //Opens serial connection at 9600bps. I2c.begin(); // Opens & joins the irc bus as master delay(100); // Waits to make sure everything is powered up before sending or receiving data I2c.timeOut(50); // Sets a timeout to ensure no locking up of sketch if I2C communication fails } void loop(){ // Write 0x04 to register 0x00 uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received ) nackack = I2c.write(LIDARLite_ADDRESS,RegisterMeasure, MeasureValue); // Write 0x04 to 0x00 delay(1); // Wait 1 ms to prevent overpolling } byte distanceArray[2]; // array to store distance bytes from read function // Read 2byte distance from register 0x8f nackack = 100; // Setup variable to hold ACK/NACK resopnses while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received ) nackack = I2c.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in array delay(1); // Wait 1 ms to prevent overpolling } int distance = (distanceArray[0] << 8) + distanceArray[1]; // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int // Print Distance Serial.println(distance); } |
PWM Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
unsigned long pulse_width; void setup() { Serial.begin(9600); // Start serial communications pinMode(2, OUTPUT); // Set pin 2 as trigger pin pinMode(3, INPUT); // Set pin 3 as monitor pin digitalWrite(2, LOW); // Set trigger LOW for continuous read } void loop() { pulse_width = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds if(pulse_width != 0){ // If we get a reading that isn't zero, let's print it pulse_width = pulse_width/10; // 10usec = 1 cm of distance for LIDAR-Lite Serial.println(pulse_width); // Print the distance } delay(20); //Delay so we don't overload the serial port } |
Continuous Mode Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <Wire.h> #define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite. #define RegisterMeasure 0x00 // Register to write to initiate ranging. #define MeasureValue 0x04 // Value to initiate ranging. #define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call. int reading = 0; void setup() { Wire.begin(); // join i2c bus Serial.begin(9600); // start serial communication at 9600bps } void loop() { Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite Wire.write((int)RegisterMeasure); // sets register pointer to (0x00) Wire.write((int)MeasureValue); // sets register pointer to (0x00) Wire.endTransmission(); // stop transmitting delay(20); // Wait 20ms for transmit Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite Wire.write((int)RegisterHighLowB); // sets register pointer to (0x8f) Wire.endTransmission(); // stop transmitting delay(20); // Wait 20ms for transmit Wire.requestFrom((int)LIDARLite_ADDRESS, 2); // request 2 bytes from LIDAR-Lite if(2 <= Wire.available()) // if two bytes were received { reading = Wire.read(); // receive high byte (overwrites previous reading) reading = reading << 8; // shift high byte to be high 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits Serial.println(reading); // print the reading } } |
Downloads
- Download i2C Library | Zip
- Download LIDAR Datasheet Version 1| PDF
- Download LIDAR Datasheet Version 2| PDF
- Download LIDAR Datasheet Version 3 | PDF