Een VL53L0X laserafstandsmeter gebruiken met Arduino
In deze tutorial onderzoeken we hoe u de VL53L0X laserafstandsmeter kunt gebruiken met een Arduino. Met dit apparaat kunt u afstanden nauwkeurig meten met behulp van een laser, waardoor het ideaal is voor verschillende toepassingen zoals robotica en automatisering. Aan het einde van deze tutorial heb je een functionele opstelling die afstanden kan meten en deze op de seriële monitor kan weergeven.

Voor ons project zullen we de Adafruit VL53L0X-bibliotheek gebruiken, die het proces van interactie met de sensor vereenvoudigt. Deze bibliotheek biedt de nodige functies om de sensor te initialiseren, metingen uit te lezen en eventuele fouten op te lossen. U kunt de video raadplegen voor een visuele handleiding over de opstelling (in video om 02:15).
Hardware uitgelegd
De belangrijkste onderdelen van dit project zijn de VL53L0X laserafstandsmeter en het Arduino-bord. De VL53L0X is een time-of-flight-sensor die met behulp van een laser afstanden tot 2 meter met hoge nauwkeurigheid meet. Het werkt via het I2C-protocol, waardoor gemakkelijke communicatie met de Arduino mogelijk is.
Het Arduino-bord dient als de microcontroller die de gegevens van de VL53L0X verwerkt. Het stuurt commando's naar de sensor en ontvangt de afstandsmetingen, die vervolgens kunnen worden weergegeven of gebruikt in andere toepassingen. Een goede bedrading is cruciaal voor het garanderen van nauwkeurige metingen van de sensor.
Details gegevensblad
| Fabrikant | STMicro-elektronica |
|---|---|
| Onderdeel nummer | VL53L0X |
| Voedingsspanning | 2,6 V tot 3,5 V |
| Bereik | 30 mm tot 2000 mm |
| Nauwkeurigheid | ±3% typisch |
| Interface | I2C |
| Temperatuurbereik | -40 °C tot +85 °C |
| Huidig verbruik | <1 mA (stand-by), 20 mA (actief) |
| Pak | VFLGA-8 |
- Zorg ervoor dat de sensor correct is gevoed (2.6 V tot 3.5 V).
- Zorg voor de juiste I2C-adresinstellingen om conflicten te voorkomen.
- Houd de sensor schoon voor nauwkeurige afstandsmetingen.
- Gebruik indien nodig geschikte pull-up weerstanden op de I2C-lijnen.
- Vermijd direct zonlicht op de sensor voor betrouwbare metingen.
Bedrading instructies

Om de VL53L0X sensor op de Arduino aan te sluiten, sluit u de VCC-pin van de sensor aan op de 5V-pin op de Arduino. De GND-pin moet worden aangesloten op de massa (GND) van de Arduino. Voor de I2C-communicatie sluit je de SDA-pin van de VL53L0X aan op de A4-pin op de Arduino en sluit je de SCL-pin aan op de A5-pin. Als je een ander Arduino-model gebruikt, raadpleeg dan de specifieke SDA- en SCL-pintoewijzingen voor dat bord.
Op de Arduino Mega zou je bijvoorbeeld SDA verbinden met pin 20 en SCL met pin 21. Zorg ervoor dat alle verbindingen veilig zijn om communicatieproblemen te voorkomen. Als de sensor niet reageert, controleer dan de bedrading en zorg ervoor dat de Arduino goed van stroom wordt voorzien.
Codevoorbeelden en walkthrough
Hieronder ziet u een fragment van de instelfunctie die de VL53L0X sensor initialiseert:
void setup() {
Serial.begin(9600);
while (! Serial) {
delay(1);
}
Serial.println("Robojax Test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
}Deze code initialiseert de seriële communicatie en probeert de VL53L0X sensor te starten. Als de sensor niet opstart, wordt een foutmelding weergegeven en wordt het programma stopgezet.
Vervolgens is hier een fragment uit de lusfunctie die de afstandsmeting leest:
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);
if (measure.RangeStatus != 4) {
Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
} else {
Serial.println(" out of range ");
}
delay(100);
}Dit blok leest continu de afstandsmeting van de sensor en drukt deze af naar de seriële monitor. Als de meting buiten het bereik valt, wordt dit dienovereenkomstig aangegeven.
Demonstratie / Wat te verwachten
Wanneer u het programma uitvoert, zou u afstandsmetingen moeten zien die worden weergegeven op de seriële monitor. De metingen moeten elke 100 milliseconden worden bijgewerkt. Als de sensor naar een object wijst, wordt de afstand in millimeters weergegeven. Als het object buiten bereik is, zal dat ook worden aangegeven. Zorg ervoor dat u de sensor binnen het gespecificeerde bereik test voor optimale resultaten (in video om 10:00 uur).
Video tijdstempels
- 00:00-Introductie
- 02:15- Bedrading instellen
- 05:30- Uitleg van de code
- 10:00-Demonstratie
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X.
// Original source from Adafruit https://github.com/adafruit/Adafruit_VL53L0X
// Modified by Ahmad Shamshiri for RoboJax.com
// Date modified: Sep 26, 2017
// Nejrabi
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place.
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* * Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Adafruit_VL53L0X.h"
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(9600);
// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}
Serial.println("Robojax 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);
}
Dingen die je misschien nodig hebt
-
AmazonPurchase VL53L0X from Amazonamzn.to
-
eBayPurchase VL53l0x from eBayebay.us
-
AliExpressPurchase 1 to 10 pcs of VL53L0X from AliExpresss.click.aliexpress.com
Hulpmiddelen en referenties
-
ExternArduino Library (GitHub)github.com
-
ExternPurchase 1 to 10 pcs of VL53L0X from AliExpresss.click.aliexpress.com
-
ExternPurchase VL53L0X from Amazonamzn.to
-
ExternPurchase VL53l0x from eBayebay.us
-
ExternVL53L0X datasheet (PDF)st.com
-
ExternVL53L0X datasheet (PDF)st.com
Bestanden📁
Fritzing-bestand
-
Adafruit VL6180X Time of Flight Distance SensorFritzing part for the Adafruit VL6180X Time of Flight distance sensor. This sensor measures absolute distance up to 100mm and ambient light, communicating via I2C. Includes the sensor breakout board and pin connections for use in Fritzing projects.
Adafruit VL6180X Time of Flight Distance Sensor-1.fzpz0.02 MB
Andere bestanden
-
Polou VL53L0X bibliotheek
robojax-VL53L0X-polou-arduino-master.zip0.02 MB