abhinav
Published © GPL3+

Arduino LIDAR

LIDAR stands for Light Detection and Ranging. LIDAR is used for many applications including 3D scanning, mapping, laser guidance, etc.

IntermediateFull instructions provided1 hour43,825
Arduino LIDAR

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
SparkFun ToF Range Finder Sensor - VL6180
SparkFun ToF Range Finder Sensor - VL6180
VL53L0X for long range and VL6180X for short range. here I used VL6180X
×1
servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE
Processing

Story

Read more

Code

Arduino code

Arduino
#include <Wire.h>
#include "Adafruit_VL6180X.h"
#include <Servo.h>
Adafruit_VL6180X vl = Adafruit_VL6180X();
Servo myservo;
float pos = 0;
const float Pi = 3.14159; 
void setup() {
   myservo.attach(9); 
  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  
 if (! vl.begin()) {   
    while (1);
  } 
}

void loop() { 

  for (pos = 0; pos <= 180; pos += .5) {  
      myservo.write(pos);
             uint8_t range = vl.readRange();
              Serial.println(String(range)+"p"+String(pos*Pi/180)+"p"+String(pos));
              delay(10);
  }
  /*for (pos = 180; pos >= 0; pos -= .5) { 
      myservo.write(pos);      
       uint8_t range = vl.readRange();
   {           
   Serial.println(String(range)+"p"+String(pos*Pi/180)+"p"+String(pos));
   delay(10);
 }
  }*/
  myservo.write(0);
  delay(1000);
}

processing code

Processing
import processing.serial.*;
Serial myPort;
String val;
int range,i=0;float pos;
void setup(){
  size(550,500);
   frameRate(36);
   String portName = "COMx";//x=your arduino port number
   myPort = new Serial(this, portName, 115200);
   background(255);
   
}
void draw(){
  if ( myPort.available() > 0) {
   val = myPort.readStringUntil('\n');   
   if(val!=null)
   {    String[] nums=split(val,"p");//splitting the recevied data searated by 'p'
           if(nums.length==3)
      {
      range=int(nums[0]); //string to integer conversion 
      pos=float(nums[1]);
      i=int(nums[2]);
     if(i==180){
   background(255);
      }
       }
   }
 }
translate(25,-50);
line(250,500,250-2*(range*cos(pos)),500-2*(range*sin(pos)));  
}

Credits

abhinav

abhinav

3 projects • 25 followers

Comments