📌 Pin Connection Guide for ZY-ESP32 / ESP32 DevKit V1:
ESP32 Connections:
- Pin 1 (3.3V): Power supply → Connect to VL53L1X power pins and pull-up resistors
- Pin 20 (GPIO21): I²C SDA data line → Connect to VL53L1X Pin 9
- Pin 23 (GPIO22): I²C SCL clock line → Connect to VL53L1X Pin 8
- Pin 11 (GPIO2): LED control → Connect to LED anode through 220Ω resistor
- Pin 19 or 25 (GND): Ground → Connect to all ground points
VL53L1X Sensor (497-17764-1-ND):
- Pin 1 (AVDD): Analog power → 3.3V
- Pin 2 (AVDDVCSEL): VCSEL laser power → 3.3V
- Pin 3 (GND): Ground → GND
- Pin 4 (AVSS): Analog ground → GND
- Pin 5 (IOVDD): I/O power → 3.3V
- Pin 6 (GPIO1): Not connected (leave floating)
- Pin 7 (XSHUT): Shutdown control → 3.3V (always enabled)
- Pin 8 (SCL): I²C clock → ESP32 GPIO22 with 10kΩ pull-up
- Pin 9 (SDA): I²C data → ESP32 GPIO21 with 10kΩ pull-up
LED Indicator Circuit:
- R3 (220Ω): Current limiting resistor for LED protection
- LED1: Any standard LED (Red recommended for visibility)
- Wiring: ESP32 GPIO2 → 220Ω Resistor → LED Anode (+, long leg) → LED Cathode (-, short leg) → GND
- Note: Your ESP32 has a built-in LED on GPIO2, so it will blink too!
🔧 Components List:
- U1: ESP32 DevKit V1 (ZY-ESP32 or compatible 30-pin board)
- U2: VL53L1X ToF Distance Sensor (Digi-Key part# 497-17764-1-ND)
- R1, R2: 10kΩ resistors (I²C pull-ups)
- R3: 220Ω resistor (LED current limiter)
- C1: 0.1µF ceramic capacitor (bypass)
- C2: 10µF electrolytic capacitor (bulk decoupling)
- LED1: Standard 5mm LED (any color, Red recommended)
- Breadboard and jumper wires
⚡ Quick Connection Summary:
- Power: ESP32 3.3V → VL53L1X Pins 1,2,5,7 + Pull-up resistors
- Ground: ESP32 GND → VL53L1X Pins 3,4 + LED cathode + Capacitors
- I²C SDA: ESP32 GPIO21 ↔ VL53L1X Pin 9 (with 10kΩ pull-up)
- I²C SCL: ESP32 GPIO22 ↔ VL53L1X Pin 8 (with 10kΩ pull-up)
- LED: ESP32 GPIO2 → 220Ω → LED(+) → LED(-) → GND
💡 How It Works:
- The VL53L1X sensor continuously measures distance using Time-of-Flight technology
- ESP32 reads distance data via I²C communication (address 0x29)
- When an object is detected within threshold distance (default 30cm), GPIO2 activates
- The external LED blinks rapidly to indicate proximity detection
- The onboard LED on GPIO2 also blinks simultaneously
- Serial monitor displays real-time distance measurements in millimeters
💻 Arduino Code Example:
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
#define LED_PIN 2 // GPIO2 - Built-in LED + External LED
#define THRESHOLD_DISTANCE 300 // 30cm in millimeters
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA=GPIO21, SCL=GPIO22
// Initialize LED pin
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.println("Proximity detector ready!");
Serial.print("Detection threshold: ");
Serial.print(THRESHOLD_DISTANCE);
Serial.println(" mm");
Serial.println();
}
void loop() {
uint16_t distance = sensor.read();
if (!sensor.timeoutOccurred()) {
// Print distance to serial monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" mm | ");
Serial.print(distance / 10.0, 1);
Serial.print(" cm");
// Check if object is within threshold and blink LED
if (distance < THRESHOLD_DISTANCE) {
Serial.println(" ⚠️ OBJECT DETECTED!");
// Blink LED rapidly
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);
} else {
Serial.println();
digitalWrite(LED_PIN, LOW);
}
} else {
Serial.println("⚠️ TIMEOUT");
}
delay(50);
}
📚 Library Installation:
- Step 1: Open Arduino IDE
- Step 2: Go to Sketch → Include Library → Manage Libraries
- Step 3: Search for "VL53L1X"
- Step 4: Install "VL53L1X by Pololu"
- Step 5: Select board: Tools → Board → ESP32 Arduino → ESP32 Dev Module
- Step 6: Select correct COM port: Tools → Port
- Step 7: Upload the code!
🔍 Troubleshooting:
- Sensor not detected:
- Check all power connections (3.3V NOT 5V!)
- Verify I²C pull-up resistors are installed
- Run I²C scanner to check address 0x29
- Ensure XSHUT pin is connected to 3.3V
- LED not blinking:
- Check LED polarity (long leg = anode = positive)
- Verify 220Ω resistor is in series with LED
- Test GPIO2 with a simple blink sketch first
- Erratic readings:
- Add capacitors close to sensor power pins
- Keep sensor away from bright lights or IR sources
- Avoid highly reflective or transparent surfaces
- Ensure stable 3.3V power supply
- Upload errors:
- Hold BOOT button while uploading (if needed)
- Check USB cable supports data transfer
- Install CH340 or CP2102 USB drivers if needed
⚙️ Customization Options:
- Change detection distance: Modify
THRESHOLD_DISTANCE (in mm)
- Adjust blink speed: Change delay values in the if statement
- Solid LED instead of blink: Remove the delay and LOW commands
- Different distance modes:
VL53L1X::Short - Up to 1.3m (best accuracy)
VL53L1X::Medium - Up to 3m (balanced)
VL53L1X::Long - Up to 4m (maximum range)
- Add buzzer: Connect to another GPIO for audio alerts
- Multiple LEDs: Use different colors for different distance ranges
⚠️ Important Notes:
- NEVER use 5V! The VL53L1X requires 3.3V only
- I²C address is 0x29 (fixed, not changeable via hardware)
- Maximum I²C clock speed: 400 kHz
- Sensor measures from 4cm to 4 meters
- GPIO2 has a built-in LED on most ESP32 boards
- Place decoupling capacitors as close to sensor as possible
- The sensor uses an infrared laser (Class 1 - safe for eyes)
🎯 Next Steps:
- Test with different objects and surfaces
- Experiment with different threshold distances
- Add WiFi connectivity for remote monitoring
- Create a web interface to display distance data
- Add an OLED display for standalone operation
- Build a parking sensor or obstacle detector
- Implement data logging to SD card