DL1EKM
Published © CC BY-NC-SA

COVID-19 Ultrasonic Distance Warning Tool

This tool signals optically and acoustically in several stages when the minimum safety distance is undershot.

BeginnerFull instructions provided1 hour11,541
COVID-19 Ultrasonic Distance Warning Tool

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
Mount the pin header below the PCB
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
If possible try to find a version with pinhead on TOP of the PCB making it easier to mount it.
×1
Buzzer
Buzzer
Check for RM 7.6mm!
×1
3 mm LED: Green
3 mm LED: Green
×5
3 mm LED: Red
3 mm LED: Red
×5
Through Hole Resistor, 470 ohm
Through Hole Resistor, 470 ohm
×10
9V Battery Clip
9V Battery Clip
×1
9V battery (generic)
9V battery (generic)
×1
Slide Switch, SPDT-CO
Slide Switch, SPDT-CO
×1
Cable Tie, Catamount®
Cable Tie, Catamount®
Chose 2 pieces fitting your needs
×2
cardboard
some strong cardboard in size of the 9V battery to prevent shortages
×1
cord
Around 60cm to hang around your neck - test it first.
×1

Story

Read more

Schematics

Schematics

Gerber files

Bill of material

Code

Source code for minimum distance warning tool

C/C++
Written within Arduino IDE use the HC-SR04 library form Martin Sosic
https://github.com/Martinsos/arduino-lib-hc-sr04
/**************************************************
 * Ultrasonic Distance Warner
 * 
 * based on HC-SR04 sonar sensor
 * 
 * 
 * Author:  Marcel Andr
 * Date:    6.7.2020
 * License: CC BY-NC-SA
 * 
 * using sonar library from Martin Sosic (https://github.com/Martinsos/arduino-lib-hc-sr04)
 */

#include <HCSR04.h>           // include Library - use the extension manager to add this library to your environment


// Define the hardware connections:
const int pin_buzzer = 9;     // pin where the buzzer is connceted to
const int pin_Echo = 8;       // digital pin for HC-SR04 echo connector
const int pin_Trigger = 7;    // digital pin for HC-SR04 Trigger connector

// Define the signalling
const int tone_repeat = 1;    // How often a tone / smile will be repeated

const int tone_low = 800;     // Frequency for tone if emergency level is low
const int time_low = 500;     // Tone duration if emergency level is low
const int dist_low = 150;     // distance level for low emergency level

const int tone_medium = 1600; // Frequency for tone if emergency level is medium
const int time_medium = 350;  // Tone duration if emergency level is medium
const int dist_medium = 100;   // distance level for medium emergency level

const int tone_high = 2400;   // Frequency for tone if emergency level is high
const int time_high = 200;    // Tone duration if emergency level is high
const int dist_high = 50;     // distance level for high emergency level

// to store the current distance:
float distance;               // distance read from ultrasonic sensor

//create an instance to control the sensor:
UltraSonicDistanceSensor distanceSensor(7, pin_Echo);  // Initialize sensor that uses digital pins 13 and 12.

/*
 *  Setup steps
 */
void setup () {
  Serial.begin(9600);     // Enabled for debzg

  // set all LED pins as output
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(A5, OUTPUT);
  pinMode(A6, OUTPUT);

  Start(200);                // Call start eequence
}



/*
 * Start Sequence
 * ==============
 *
 * Params:
 * -------
 *  startpeed: time in milliseconds between each LED step
 * 
 */
void Start(int startspeed) {
  digitalWrite(3,HIGH);
  delay(startspeed);
  digitalWrite(4,HIGH);
  delay(startspeed);
  digitalWrite(6,HIGH);
  delay(startspeed);
  digitalWrite(A4,HIGH);
  delay(startspeed);
  digitalWrite(12,HIGH);
  delay(startspeed);

  digitalWrite(2,HIGH);
  delay(startspeed);
  digitalWrite(5,HIGH);           
  delay(startspeed);
  digitalWrite(A5,HIGH);
  delay(startspeed);
  digitalWrite(10,HIGH);   
  delay(startspeed);
  digitalWrite(11,HIGH);
  delay(startspeed);

  delay(500);

  digitalWrite(12,LOW);
  delay(startspeed);
  digitalWrite(A4,LOW);
  delay(startspeed);
  digitalWrite(6,LOW);
  delay(startspeed);
  digitalWrite(4,LOW);
  delay(startspeed);
  digitalWrite(3,LOW);
  delay(startspeed);

  digitalWrite(11,LOW);
  delay(startspeed);
  digitalWrite(10,LOW);  
  delay(startspeed);        
  digitalWrite(A5,LOW);
  delay(startspeed);
  digitalWrite(5,LOW); 
  delay(startspeed); 
  digitalWrite(2,LOW);
  delay(startspeed);
}

/*
 * Set all green LEDs on
 */
void greenSmile() {
  digitalWrite(3,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(6,HIGH);
  digitalWrite(12,HIGH);
  digitalWrite(A4,HIGH);
  digitalWrite(2,LOW);
  digitalWrite(5,LOW);           
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);   
  digitalWrite(A5,LOW);
}

/*
 * Set all red LEDs on
 */
void redSmile() {
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  digitalWrite(6,LOW);
  digitalWrite(12,LOW);
  digitalWrite(A4,LOW);
  digitalWrite(2,HIGH);
  digitalWrite(5,HIGH);           
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);   
  digitalWrite(A5,HIGH);
}


/*
 * Set all LEDs off
 */
void offSmile() {
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  digitalWrite(6,LOW);
  digitalWrite(12,LOW);
  digitalWrite(A4,LOW);
  digitalWrite(2,LOW);
  digitalWrite(5,LOW);           
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);   
  digitalWrite(A5,LOW);
}

/*
 * Signal to short distance
 * ========================
 *
 * Params:
 * -------
 *  level: "loudness" of signaling -> 0 (off), 1 (low),2 (medium) or 3 (high)
 * 
 */

void emergency(int level) {
  switch (level) {
    case 0:             // off
      greenSmile();
      break;
    case 1:             // low
      for (int i = 1; i <= tone_repeat; i++) {
        tone (pin_buzzer, tone_low, time_low);
        redSmile();
        delay (time_low);
        offSmile();
        delay (time_low);
      }
      break;
    case 2:             // medium
      for (int i = 1; i <= tone_repeat; i++) {
        tone (pin_buzzer, tone_medium, time_medium);
        redSmile();
        delay (time_medium);
        offSmile();
        delay (time_medium);
      }
      break;
    case 3:             // high
      for (int i = 1; i <= tone_repeat; i++) {
        tone (pin_buzzer, tone_high, time_high);
        redSmile();
        delay (time_high);
        offSmile();
        delay (time_high);
      }   
      break;
    default:            // default = off
      greenSmile();
      delay (time_low);
      break;
  }
}



/*
 * The main programm loop:
 * 
 * - read current distance
 * - compare with distance intervals defined above
 * - call signalling (emergency) routine to set smiling and beeping
 */
void loop () {
    distance = distanceSensor.measureDistanceCm();  // read current distance
    Serial.println(distance);                       // output for debug

    // check interval:
    if (distance <= dist_high)
    {
      emergency(3);
    }
    else if (distance <= dist_medium)
    {
      emergency(2);
    }
    else if (distance <= dist_low)
    {
      emergency(1);
    }
    else if (distance > dist_low)
    {
      emergency(0);
    }
    delay(100);                                       // wait a bit :-)
}

Credits

DL1EKM

DL1EKM

4 projects • 3 followers

Comments