Arca_Ege
Published © GPL3+

Social Distancing Reminder – Coronavirus

This reminds people to keep a 2-meter distance from you

IntermediateFull instructions provided3,986
Social Distancing Reminder – Coronavirus

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Arduino Nano works better for this, but I have used an Arduino UNO.
×1
Arduino Proto Shield
Arduino Proto Shield
I used it, but it's optional.
×1
Adafruit Mini Breadboard
×1
Elegoo 16 x 2 LCD Display
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Touch sensor
You can also use a button, but you'll need a pull-down resistor.
×1
NTC Thermistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Buzzer
Buzzer
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
This is to adjust the contrast of the LCD.
×1
Jumper wires (generic)
Jumper wires (generic)
×1
A transparent box to put everything into
It needs to be transparent for you to be able to see the LCD and it needs to be waterproof to light rain
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring

coronavirus_distancing_MA0bILE8zp.jpg

Code

The Code

Arduino
Upload it to the Arduino.
#include <HCSR04.h>
#include <LiquidCrystal.h>
#define trigPin 7
#define echoPin 6
#define buzzer 9
#define backlight 10

LiquidCrystal lcd(12, 11, 5, 4, 3, 8);
UltraSonicDistanceSensor distanceSensor(trigPin, echoPin);

int tempReading;
double tempK;
float tempC;
int rounded;
int temp_round;
volatile boolean modes = 0;
double distance;

void setup() {
  lcd.begin(16, 2);
  attachInterrupt(0, changeMode, FALLING);
  pinMode(2, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(backlight, OUTPUT);
  digitalWrite(backlight, HIGH);
  backlightOn();
}

void loop() {
  tempReading = analogRead(A0);
  tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK );
  tempC = tempK - 273.15;
  distance = distanceSensor.measureDistanceCm(tempC);
  temp_round = round(tempC);
  if (modes == 1) {
    backlightOn();
    if (distance >= 300 || distance <= 0) {
      rounded = 0;
      lcd.clear();
      lcd.print("Out of range");
      lcd.setCursor(0, 1);
      lcd.print("Temperature:" + String(temp_round) + " C");
    }
    else {
      rounded = round(distance);
      lcd.clear();
      lcd.print("Distance: ");
      lcd.print(rounded);
      lcd.print(" cm");
      lcd.setCursor(0, 1);
      lcd.print("Temperature:" + String(temp_round) + " C");
    }
  } else {
    if (distance >= 300 || distance <= 0) {
      rounded = 0;
      lcd.clear();
      backlightOff();
    }
    else {
      rounded = round(distance);
      if (distance >= 200) {
        backlightOff();
        lcd.clear();
      }
      else if (distance <= 200 && distance > 100) {
        backlightOn();
        lcd.clear();
        lcd.print("Please keep away");
        lcd.setCursor(0, 1);
        lcd.print("Distance:");
        lcd.print(rounded);
        lcd.print(" cm");
      }
      else if (distance <= 100 && distance > 50) {
        backlightOn();
        lcd.clear();
        lcd.print("Keep away");
        lcd.setCursor(0, 1);
        lcd.print("Distance:");
        lcd.print(rounded);
        lcd.print(" cm");
        delay(200);
        buzz();
        backlightOff();
        delay(100);
        unbuzz();
        backlightOn();
        delay(100);
      }
      else if (distance <= 50) {
        backlightOn();
        lcd.clear();
        lcd.print("STAY AWAY!");
        lcd.setCursor(0, 1);
        lcd.print("Distance:");
        lcd.print(rounded);
        lcd.print(" cm");
        delay(200);
        buzz();
        backlightOff();
        delay(200);
        unbuzz();
        backlightOn();
        delay(200);
        buzz();
        backlightOff();
        delay(200);
        unbuzz();
        backlightOn();
      }
    }
  }
  delay(700);
}

void changeMode() {
  modes = !modes;
}

void backlightOn() {
  digitalWrite(backlight, HIGH);
}

void backlightOff() {
  digitalWrite(backlight, LOW);
}

void buzz() {
  digitalWrite(buzzer, HIGH);
}

void unbuzz() {
  digitalWrite(buzzer, LOW);
}

arduino-lib-hc-sr04-master.zip

LiquidCrystal.zip

Credits

Arca_Ege

Arca_Ege

2 projects • 16 followers

Comments