Makerming
Published © MIT

Pocket Distance Alarm: Keep 1m Away from Me - Seeeduino Xiao

A portable distance alarm that will give light and sound warning when people get into your one meter circle.

IntermediateFull instructions provided10 hours13,904

Things used in this project

Hardware components

Seeed Studio Seeeduino XIAO
×1
Seeed Studio Grove - LED Pack
×1
Seeed Studio Grove - Buzzer
×1
Seeed Studio Grove - Time of Flight Distance Sensor(VL53L0X)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Electric Soldering Iron

Story

Read more

Custom parts and enclosures

distance_alarm_llsItnJYgy.dxf

Schematics

_f3YT9f5yAJ.png

Code

Distance_Alarm_Makerming.ino

Arduino
const int Buzzer = 8;// D8
const int LED = 7;//LED D7

#include "Seeed_vl53l0x.h"
Seeed_vl53l0x VL53L0X;  //tof   IIC D4 D5   

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif

void setup() {

    pinMode(Buzzer, OUTPUT);
    pinMode(LED, OUTPUT);
    digitalWrite(Buzzer, LOW);   // turn the Buzzer on (HIGH is the voltage level)
    digitalWrite(LED, LOW);   // turn the LED on (HIGH is the voltage level)
            

    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);   // turn the Buzzer on (HIGH is the voltage level)
            digitalWrite(LED, LOW);   // turn the LED on (HIGH is the voltage level)
            
        } 
           else if (RangingMeasurementData.RangeMilliMeter <= 1000) {
            digitalWrite(Buzzer, HIGH);   // turn the Buzzer on (HIGH is the voltage level)
            digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
            SERIAL.print("Distance:");
            SERIAL.print(RangingMeasurementData.RangeMilliMeter);
            SERIAL.println(" mm");
           } 
              else {    
                  digitalWrite(Buzzer, LOW);   // turn the Buzzer on (HIGH is the voltage level)
                  digitalWrite(LED, LOW);   // turn the LED on (HIGH is the voltage level)
                  SERIAL.print("Distance:");
                  SERIAL.print(RangingMeasurementData.RangeMilliMeter);
                  SERIAL.println(" mm");
              }

    }
    else {
        SERIAL.print("mesurement failed !! Status code =");
        SERIAL.println(Status);
        digitalWrite(Buzzer, LOW);   // turn the Buzzer on (HIGH is the voltage level)
        digitalWrite(LED, LOW);   // turn the LED on (HIGH is the voltage level)
        
    }

    delay(250);
    
    
}

Credits

Makerming

Makerming

11 projects • 30 followers
Maker, DIYer, Opensource Hardware Enthusiast

Comments