ProPeppone12
Created August 26, 2020

Security Distance

Small distance detector to accentuate social distancing and safeguard health. The device activates below one meter. Simple but very useful.

BeginnerFull instructions provided37
Security Distance

Things used in this project

Hardware components

Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The Schematics

The schematics for the connection

Code

The Code

Arduino
The code in the Arduino Nano
#define Trigger 7 // define the trigger pin of the HC-SR04
#define Echo 6    // define the echo pin of the HC-SR04

#define Led 11    // define the anode pin of the led

#define Buzzer 13 // define the anode pin of the buzzer

void setup() {
  
  pinMode(Trigger, OUTPUT);  // Configure the trigger pin of the HC-SR04
  pinMode(Echo, INPUT);      // Configure the echo pin of the HC-SR04

  pinMode(Led, OUTPUT);      // Configure the Led

  digitalWrite(Trigger, LOW);// Prepare the HC-SR04
  
  }

void loop() {

  digitalWrite(Trigger, HIGH);  //   Active and the trigger
  delayMicroseconds(10);        //   pin on the HC-SR04 and
  digitalWrite(Trigger, LOW);   //   deactive it after 10 microseconds

  unsigned long Ultrasonic_Sensor_Time = pulseIn(Echo, HIGH);  // calculate the
  float meters = 0.0003438 * Ultrasonic_Sensor_Time / 2;       // distance in meters

  if(meters <= 1){                          // when the meters
                                            // are less than 1
    digitalWrite(Led, HIGH);                // the led lights up
    tone(Buzzer, 1000, 100);                // and the buzzer
    delay(100);                             // sounds
    
  }else{                                    // when the meters
                                            // are more than 1
    digitalWrite(Led, LOW);                 // the led turn off
      
  }

  delay(100);                               // a little delay

}

Credits

ProPeppone12

ProPeppone12

1 project • 0 followers

Comments