Thecoder111
Created May 13, 2020

SafeDistance Detector

Keep a safe distance from other people with this detector.

SafeDistance Detector

Things used in this project

Story

Read more

Schematics

Schematics

Schematics

Code

Code

C/C++
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;

long duration;
int distance;
int SafeDistance;

void setup() {
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
pinMode(buzzer, OUTPUT);

Serial.begin(9600); 
}

void loop() {

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;

SafeDistance = distance;
if (SafeDistance <= 180){ //Type the Distance 
  digitalWrite(buzzer, HIGH);
  Serial.println("Person 6 feet in front of you.");
}
else{
  digitalWrite(buzzer, LOW);
  
}

Serial.print("Distance: ");
Serial.println(distance);
}

Credits

Thecoder111

Thecoder111

0 projects • 0 followers

Comments