Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Maksym BuryakEnzo Trevizan
Published © MIT

Radar with LiDAR sensor

A radar built using Power-KI, Arduino and LIDAR-Lite sensor.

IntermediateFull instructions provided2 hours10,383
Radar with LiDAR sensor

Things used in this project

Story

Read more

Schematics

Diagram

Wiring

Code

Arduino Sketch

Arduino
Upload this sketch to your Arduino board
#include <Servo.h>
#include <Wire.h>
#include <LIDARLite.h>

unsigned short crv[3];
#define HEADSAM 0xFAFB
#define CRV_HEAD crv[0]
#define CRV_ANGL crv[1]
#define CRV_DIST crv[2]
byte* buff;

#define SERVO_PIN 9  

Servo myservo;
int pos = 0;
bool servoAlive = true;

LIDARLite lidarLite;
int cal_cnt = 0;

void setup() {
  Serial.begin(9600);
  myservo.attach(SERVO_PIN);
  myservo.write(0);
  
  CRV_HEAD = HEADSAM;
  buff= (byte*) crv;
  
  lidarLite.begin(0, true);
  lidarLite.configure(0);
}

int readLidar() {
  int dist;
  if ( cal_cnt == 0 ) {
    dist = lidarLite.distance();
  } else {
    dist = lidarLite.distance(false);
  }
  cal_cnt++;
  cal_cnt = cal_cnt % 100;
  return dist;
}

void loop() {
  if(servoAlive){
    if (pos >= 180) {
      pos = 0;
    } else {
        pos++;
    }
    myservo.write(pos);
  }
  delay(15);

  CRV_ANGL = pos;
  CRV_DIST = readLidar();
  Serial.write(buff, 10);
  
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    if(incomingByte == 0) {
        servoAlive = false;
    }
    if(incomingByte == 1) {
        servoAlive = true;
    }
  }
}

Power-KI Package

Plain text
No preview (download only).

LIDARLite Arduino Library

Servo Arduino Library

Credits

Maksym Buryak
3 projects • 1 follower
Enzo Trevizan
2 projects • 0 followers

Comments