Introduction: Covid Distancing Calculator

First things first... Why would I make something so dumb... well when your couped up in a house for 8 months you start going a little bit crazy. With the amount of people scared of this virus I need a way to tell if I'm distanced correctly so that the virus knows not to attack me, because I'll be abiding by the social distancing guidelines that have been put in place in many areas of the world.

So how did I come up with the idea? Well, I was pondering about what I could create with the sensors that happened to come with my elegoo arduino super starter kit. I saw that there was an ultrasonic sensor that can detect distance and the thought popped into my head with the pandemic in mind, " omg! I can use the ultrasonic sensor to tell if I am too close to someone or not." So, that was how I came up with the idea and then I knew that I could map the change in numbers to the RGB LED to create a sort of warning method being red when you are too close and green when you are distanced correctly.


There are a couple of flaws with using the ultrasonic sensor... it detects the measurement of an object, but that object doesn't have to be a human so it will keep you 6ft away from the walls and other objects as well as people haha.


  • Arduino
  • Wires (Preferably different colors for easy visual characterization of what each colored wire is doing.)
  • Ultrasonic Sensor
  • Buttons
  • 9 Volt battery for sufficient power for when you go outside in the scary world.

Step 1: Plug Wires Initial Wires Where They Need to Go!

So, first thing ya gotta do to create the Covid distancing calculator is you have to take your Ultrasonic sensor, plug the female ends of your Male to Female wires into the sensor and then connect the wires to the arduino.

You're going to plug echo and trig into the pinMode pins so hold those off for now. Plug the ground wire and Vcc into their corresponding places as the pictures above show. Although the echo and trig wires should be switched in this photo I messed that up when rewiring at the end. Echo goes into pin 11 and trig goes into pin 12.

Step 2: Buttons, RGB LED


  1. Put RGB LED into breadboard
  2. Wire ground to ground rail.
  3. Wire blue to pin 3
  4. Wire green to pin 5
  5. Wire red to pin 6


  1. Place buttons into breadboard
  2. Wire orange to pin 8
  3. Wire yellow to pin 9
  4. Wire ground wires to ground rail
  5. Wire ground rail to ground

Step 3: Arduino Code

// Covid Distancing Calculator

// by Taylor Mittelstadt

// Mashing up code from multiple elegoo

// tutorial example .ino files

#include "SR04.h"

#define TRIG_PIN 12

#define ECHO_PIN 11

#define BLUE 3

#define GREEN 5

#define RED 6

int buttonApin = 9;

int buttonBpin = 8;

SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN); // stuff for ultrasonic sensor long a

void setup()


pinMode(buttonApin, INPUT_PULLUP); // On button

pinMode(buttonBpin, INPUT_PULLUP); // off button

pinMode(RED, OUTPUT);


pinMode(BLUE, OUTPUT);

Serial.begin(9600);//Initialization of Serial Port



//define variables

int redValue;

int greenValue;

int blueValue;

// main loop

void loop() {



Serial.println("cm");//The difference between "Serial.print" and "Serial.println"

//is that "Serial.println" can change lines.

if (digitalRead(buttonApin) == LOW) {

greenValue = map(a, 0, 255, 1 ,190);

analogWrite(GREEN, greenValue);

redValue = map(a, 0, 255, 190 ,1000);

analogWrite(RED, redValue);

delay(1000); }

if (digitalRead(buttonBpin) == LOW) {

digitalWrite(RED, LOW);

digitalWrite(BLUE, LOW);

digitalWrite(GREEN, LOW);



Step 4: Laugh at How Dumb Your Creation Is While Testing It