Makerming
Published © MIT

Pocket Distance Alarm V2 - Seeeduino XIAO

Pocket Distance Alarm using Grove Shield for Seeeduino XIAO, no jumper wire soldering any more!

BeginnerFull instructions provided3 hours4,154

Things used in this project

Hardware components

Seeed Studio SeeeduinoXIAO
×1
Seeed Studio Grove Shield for Seeeduino XIAO - with embedded battery management chip
×1
Seeed Studio Grove - Circular LED
×1
Grove - Vibration Motor
Seeed Studio Grove - Vibration Motor
×1
Seeed Studio Grove - Time of Flight Distance Sensor(VL53L0X)
×1
Rechargeable Battery, 3.7 V
Rechargeable Battery, 3.7 V
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

hardware_connection_ok35LV8be0.png

Code

Distance_Alarm_Makerming.ino

C/C++
#include "Seeed_vl53l0x.h"  //https://github.com/Seeed-Studio/Grove-Ranging-sensor-VL53L0X
Seeed_vl53l0x VL53L0X;  //tof   IIC (D4 D5)   
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif

const int Buzzer = 8;//buzzer D8

void setup() {

    pinMode(Buzzer, OUTPUT);
    digitalWrite(Buzzer, LOW);

    VL53L0X_Error Status = VL53L0X_ERROR_NONE;
    SERIAL.begin(115200);
    Status = VL53L0X.VL53L0X_common_init();
    if (VL53L0X_ERROR_NONE != Status) {
        SERIAL.println("start vl53l0x mesurement failed!");
        VL53L0X.print_pal_error(Status);
        while (1);
    }

    VL53L0X.VL53L0X_long_distance_ranging_init();

    if (VL53L0X_ERROR_NONE != Status) {
        SERIAL.println("start vl53l0x mesurement failed!");
        VL53L0X.print_pal_error(Status);
        while (1);
    }
}

void loop() {

    VL53L0X_RangingMeasurementData_t RangingMeasurementData;
    VL53L0X_Error Status = VL53L0X_ERROR_NONE;

    memset(&RangingMeasurementData, 0, sizeof(VL53L0X_RangingMeasurementData_t));
    Status = VL53L0X.PerformSingleRangingMeasurement(&RangingMeasurementData);
    if (VL53L0X_ERROR_NONE == Status) {
        if (RangingMeasurementData.RangeMilliMeter >= 2000) {
            SERIAL.println("out of range!!");
            digitalWrite(Buzzer, LOW);        
        } 
           else if (RangingMeasurementData.RangeMilliMeter <= 1000) {
            digitalWrite(Buzzer, HIGH);   // turn the Buzzer on (HIGH is the voltage level)
            SERIAL.print("Distance:");
            SERIAL.print(RangingMeasurementData.RangeMilliMeter);
            SERIAL.println(" mm");
           } 
              else {    
                  digitalWrite(Buzzer, LOW);   
                  SERIAL.print("Distance:");
                  SERIAL.print(RangingMeasurementData.RangeMilliMeter);
                  SERIAL.println(" mm");
              }

    }
    else {
        SERIAL.print("mesurement failed !! Status code =");
        SERIAL.println(Status);
        digitalWrite(Buzzer, LOW);   
    }
    delay(250); 
}

Credits

Makerming

Makerming

10 projects • 21 followers
Maker, DIYer, Opensource Hardware Enthusiast

Comments