VL53L0X Laser Ranging Sensor Test
by Tech_Demons in Circuits > Arduino
437 Views, 1 Favorites, 0 Comments
VL53L0X Laser Ranging Sensor Test
This project only changes the sensor's working condition. That project maser or calculate distance.
Supplies
Requirements of test that sensor.
- Arduino uno _ https://amzn.to/4azgMO3 /Esp32 :- https://amzn.to/43GORth /Nedemcu :- https://amzn.to/4cw4YOF
- VL53L0X Laser Ranging Sensor :- https://amzn.to/3xkYcv2
- jumper wire :- https://amzn.to/4aBS2VI
- Breadboard :- https://amzn.to/43Gp2Kb
Connections
Connect the VL53L0X sensor to the ESP32 as follows:
- VL53L0X VCC -> ESP32 3.3V
- VL53L0X GND -> ESP32 GND
- VL53L0X SDA -> ESP32 GPIO21
- VL53L0X SCL -> ESP32 GPIO22
Installing Libraries
You need to install the necessary libraries for the VL53L0X sensor. You can use the "Adafruit_VL53L0X" library. To install it, open Arduino IDE, go to "Sketch" -> "Include Library" -> "Manage Libraries", then search for "Adafruit VL53L0X" and install it.
Uploading Code for ESP32
// that coad for esp32 board
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(1);
}
Serial.println("Adafruit VL53L0X test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
// power
Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
Serial.print("Reading a measurement... ");
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
if (measure.RangeStatus != 4) { // phase failures have incorrect data
Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
} else {
Serial.println(" out of range ");
}
delay(100);
}
Interpreting Results
Open the Serial Monitor (Tools -> Serial Monitor) at a baud rate of 115200. You should see distance readings in millimeters.
Output
The distance show in the Serial Monitor as show in above image.