Laser Ranging Sensor(4m)Arduino WiKi - DFRobot

Introduction

This laser distance sensor is specifically designed to address the issues commonly found in distance sensors on the market, such as large size, slow response time, and poor installation adaptability. It has a compact size, comparable to the size of a fingernail, and a measurement range of up to 4m. It boasts a range of advantages including small size, minimal blind zone, fast response time, high installation adaptability, dust and water resistance, long lifespan, and high reliability.

The sensor outputs data through an I2C interface, which allows users to easily integrate it with Arduino IO expansion boards. It finds widespread applications in various fields, including smart furniture with motion sensing capabilities, home security systems, intelligent detection systems, smart control systems, robot obstacle avoidance, and object proximity and presence detection.

Features

Specification

Board Overview

Num Label Description
Red line VCC power supply input positive pole
Black line GND power ground wire
Yellow line SCL I2C clock line SCL
Green line SDA I2C data line SDA

Dimensional Drawing

Installation opening suggestion

Tutorial

Requirements

Connection Diagram

Connection Diagram

Sample Code

#include "Wire.h"
#define address 0x74

uint8_t buf[2] = { 0 };

void setup() {
  Serial.begin(115200);
  Wire.begin();
}

uint8_t dat = 0xB0;
int distance = 0;


void loop() {
  writeReg(0x10, &dat, 1);
  delay(50);
  readReg(0x02, buf, 2);
  distance = buf[0] * 0x100 + buf[1] + 10;
  Serial.print("distance=");
  Serial.print(distance);
  Serial.print("mm");
  Serial.println("\t");
  delay(100);
}

uint8_t readReg(uint8_t reg, const void* pBuf, size_t size) {
  if (pBuf == NULL) {
    Serial.println("pBuf ERROR!! : null pointer");
  }
  uint8_t* _pBuf = (uint8_t*)pBuf;
  Wire.beginTransmission(address);
  Wire.write(&reg, 1);
  if (Wire.endTransmission() != 0) {
    return 0;
  }
  delay(20);
  Wire.requestFrom(address, (uint8_t)size);
  for (uint16_t i = 0; i < size; i++) {
    _pBuf[i] = Wire.read();
  }
  return size;
}

bool writeReg(uint8_t reg, const void* pBuf, size_t size) {
  if (pBuf == NULL) {
    Serial.println("pBuf ERROR!! : null pointer");
  }
  uint8_t* _pBuf = (uint8_t*)pBuf;
  Wire.beginTransmission(address);
  Wire.write(&reg, 1);

  for (uint16_t i = 0; i < size; i++) {
    Wire.write(_pBuf[i]);
  }
  if (Wire.endTransmission() != 0) {
    return 0;
  } else {
    return 1;
  }
}

Expected Results

View the distance value detected by the sensor through the serial port.

Result

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Mini Laser Distance Range Sensor (4m, I2C, IP67) from DFRobot Store or DFRobot Distributor.

Turn to the Top