alexanderlei
Published © GPL3+

Social Distance Detector

How to detect if impostors are sus.

BeginnerFull instructions provided17,395
Social Distance Detector

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5 mm LED: Red
5 mm LED: Red
any Led colour can be used but I find red to be the most suitable
×1
Buzzer, Piezo
Buzzer, Piezo
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
Any sized breadboard can be used but I just used mini
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

TinkerCad Model

Code

Code For The Project

C/C++
const int trigPin = 9; //pin for sensor, trig pin transmits signal to object in front of it
const int echoPin = 10; //pin for sensor, echo pin receives the signal the object reflects and therefore the distance is measured
const int ledPin = 13; //led pin on arduino
const int buzzPin = 2; //buzzer pin on arduino
long duration; //distance variable
int distance;
void setup()
{
Serial.begin(9600); 
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT); 
pinMode(buzzPin, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); //trigpin's output pulse
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); //calibrate echo pin's pulse input
distance= duration*0.034/2; // distanceCm is half the duration multiplied by 0.034
Serial.println("Distance: "); //print to serial monitor
Serial.println(distance); //print distance in Cm to the serial monitor
delay(500); //so you don't get overloaded by serial monitor outputs


if (distance <= 150 && distance >= 0) { //if distance from sensor to object is less than 150cm and more than 0

digitalWrite(ledPin, HIGH); //light led
digitalWrite(buzzPin, HIGH); //buzz
tone(2, 500, 120); //so we can hear a sound from the buzzer that isn't inaudible
//buzz and light LED
} else {
//dont buzz or light LED
digitalWrite(ledPin, LOW); //don't light led
digitalWrite(buzzPin, LOW); //don't buzz
}
}

Credits

alexanderlei

alexanderlei

1 project • 2 followers

Comments