Covid-19 Safe Distance Detector

by 739693 in Circuits > Arduino

399 Views, 4 Favorites, 0 Comments

Covid-19 Safe Distance Detector

Final Project.png
image_50393089.JPG

In this Instructable, I show how to make a Covid-19 safe distance detector. The purpose of this project is to let a person know if they are within 6 feet of another person, so they know if they are at risk of potentially catching covid-19. This project was inspired by another person who made a "COVID-19 Social Distance Meter".

Supplies

You will need:

What they do:

Arduino Uno: An Arduino is a simple microcontroller that can be used to make simple or complex circuits with functionality.

Breadboard: A breadboard is a board with holes in it that can be used to make circuits

Led: An Led stands for light-emitting diode which emits light

RGB Led: Just like a regular led it emits light, but now in 3 colors, red, green, and blue, it can be used to make virtually any color.

Push-button: A push button is a switch that makes no contact with the circuit until pressed

Resistors: A resistor is a component in a circuit that is used to limit the current

Ultrasonic distance sensor: An electrical device used to measure the distance of an object by using sound waves

LCD display: An electronic display module used to produce words or even images

Potentiometer: A component in a circuit that can be used as a voltage divider

Processes used:


PWM: Pulse width modulation or PWM is used as a technique to control an analog circuit by digital outputs, for example, digitalWrite values can only be HIGH or LOW, but analogWrite values can be from 0-255, but the problem is that digitals circuits can only have on or off values so PWM is used to fix this problem. (ex: the RGB Led uses PWM because the Led's have an analog value so it can produce almost any color)

Distance: An ultrasonic distance sensor sends a sound wave to an object, and it measures the amount of time it takes for the sound wave to come back; this is used to determine the distance, which can be converted into inches, cm, feet, etc.

The On/Off State

Screenshot (68).png

The first step in making this project is to make an on/off state because you don't want to have the project running at all times. For this step, you will need to have an Arduino Uno, a small breadboard, a led, a 330-ohm resistor, a 10k-ohm resistor, and wires.

The LED will act as an indicator to determine if the pushbutton is in the on or off state. While on, the LED will light up, and when off the LED will turn off.

Ultrasonic Distance Sensor

Screenshot (69).png

Now that there is an on/off state, it's time to make it have some functionality.

The circuit should work as follows: when the button is in the "on" state, the rest of the components in the circuit such as the distance sensor, LCD display, and RGB led should turn on, but when it's in the "off" state, the components turn off. For this step, you will need an RGB led, an ultrasonic distance sensor, and wires.

After all, the components are added, you can use the distance sensor to change the color of the RGB Led, for example, if the distance in the distance sensor is above 6 feet, the RGB led will light up green, but if the distance is less than 6 feet, the RGB led will light up red.

The LCD Display

Screenshot (70).png

The last part of the circuit is to connect the LCD display. For this part, you will need a 16x2 LCD display, a 10k ohm potentiometer, a 330-ohm resistor, and wires.

What the LCD display would do is that it will display a certain message depending on the distance in the distance sensor. For example, if the distance is greater than 6 feet, the LCD display would display "Safe distance!" but if it's less than 6 feet it would display "Not safe distance!".

The Code

Now that all the physical components of the circuit are added, it is time for the code because without the coding the circuit would not accomplish anything. The things that are needed to be coded are the on/off state, the led turning on when in the "on state", the ultrasonic distance sensor detecting the distance in feet, the distance displaying on the serial monitor, the RGB led changing colors depending on the distance, and finally, the LCD display displaying a message depending on the distance.

// this is an additonal library added to make the LCD display work
#include <LiquidCrystal.h>

// connecting the analong input pins to a variable
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int PushButton = 12; // these are constant integers
const int Led = 13; // these are constant integers

int trigger = 2;
int echo = 3;
int red = 11;
int green = 9;
int blue = 10;
int ButtonState = 0;
int PreviousButtonState = 0; 
int LedEnabled = 0;

void setup()
{
  Serial.begin(9600);
  // this sets up the amount of collums and rows the lcd display has
  lcd.begin(16, 2);
  pinMode(Led, OUTPUT);
  pinMode(PushButton, INPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
}

void ColorSet(int r, int g, int b)
{
  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);
}


void loop()
{
  ButtonState = digitalRead(PushButton);
  if (ButtonState != PreviousButtonState)
  {
    if (ButtonState == HIGH) 
    {
      LedEnabled = !LedEnabled;
    } 
    delay(50);
  }

  
  if(LedEnabled == 1)
  {
    // turns on the rest of the components
    digitalWrite(Led, HIGH);
    long duration, distance;
    
    digitalWrite(trigger, LOW);
    delayMicroseconds(10); // this is a delay but in microseconds
    //instead of milliseconds
    
    digitalWrite(trigger, HIGH);
    delayMicroseconds(10); 
    digitalWrite(trigger, LOW);
  
    duration = pulseIn(echo, HIGH);
    distance = (duration/74)/2; // formula to get inches from the microseconds
    distance = distance/12; // formula to get feet from inches
    Serial.println(distance);
    
    if (distance >= 6)
    {
      ColorSet(0,255,0); // green
      lcd.setCursor(0, 0);
    // this is how a message is printed onto the display
    lcd.print(" Safe distance! ");
    lcd.setCursor(0, 2);
    lcd.print("                 ");
    }
    else
    {
      ColorSet(255,0,0); // red
      lcd.setCursor(0, 0);
      lcd.print("      Not       ");
      lcd.setCursor(0, 2);
      lcd.print(" safe distance! ");
    }
    
  }  
  else
  {
    // turns off the components
    digitalWrite(Led, LOW);
    ColorSet(0,0,0); // off
    lcd.clear(); // this clears the lcd display
  }
  PreviousButtonState = ButtonState; 
} <br>