Evan Rust
Published © GPL3+

Social Distancing Radar

A mobile radar unit that scans an area and displays a message to people who are too close.

BeginnerFull instructions provided5 hours2,492

Things used in this project

Hardware components

Teensy 4.0 Development Board
Teensy 4.0 Development Board
×1
LED Dot Matrix Display, Red
LED Dot Matrix Display, Red
×4
SparkFun VL53L1X
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE
VS Code
Microsoft VS Code

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Social Distancing Radar

Schematics

Board

Code

Social Distancing Radar

C/C++
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <PWMServo.h>
#include <ComponentObject.h>
#include <RangeSensor.h>
#include <SparkFun_VL53L1X.h>
#include <vl53l1x_class.h>
#include <vl53l1_error_codes.h>
#include <Wire.h>
#include "SparkFun_VL53L1X.h"

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define PANEL_COUNT 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10

#define SHUTDOWN_PIN 2 // optional
#define INTERRUPT_PIN 3 // optional
#define SERVO_PIN 9

#define MID_ANGLE 120

SFEVL53L1X distanceSensor;
PWMServo servo;

MD_Parola display = MD_Parola(HARDWARE_TYPE, CS_PIN, PANEL_COUNT);

const int16_t distanceThreshold = 2000; // stay 2m apart
const uint8_t angleDelta = 30; // go from 90-30 to 90+30

const char* message = "BACK";

uint8_t currentAngle = MID_ANGLE - angleDelta;
bool servoDirection = 0, changePossible = false;

void setup() {
    Serial.begin(115200);
    display.begin();
    Wire.begin();
    if(!distanceSensor.begin())
        Serial.println("Sensor online!");
    servo.attach(SERVO_PIN);
    showOKMessage();
}

void loop() {
    if(currentAngle < MID_ANGLE - angleDelta) {
        currentAngle = MID_ANGLE - angleDelta;
        servoDirection = !servoDirection;
    } else if(currentAngle > MID_ANGLE + angleDelta) {
        currentAngle = MID_ANGLE + angleDelta;
        servoDirection = !servoDirection;
    } else {
        if(servoDirection) currentAngle--;
        else currentAngle++;
    }
    servo.write(currentAngle);
    delay(50);
    if(measureDistance()) showBackMessage();
    else showOKMessage();
}

bool measureDistance() {
    distanceSensor.startRanging();
    int distance = distanceSensor.getDistance();
    distanceSensor.stopRanging();
    Serial.printf("Distance (mm): %d\n", distance);
    if(distance < distanceThreshold && distance != 0)
        return true;
    return false;
}

void showOKMessage() {
    if(!changePossible) display.print("U GOOD");
    changePossible = true;
}

void showBackMessage() {
    if(changePossible) display.print(message);
    changePossible = false;
}

Credits

Evan Rust

Evan Rust

122 projects • 1079 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments