Abdulrahman mahmoud
Published © GPL3+

Ultrasonic detector

This is my first project in hackster

BeginnerProtip-60 minutes154
Ultrasonic detector

Things used in this project

Story

Read more

Schematics

my d

Code

my code

Arduino
const int trig = 7;
const int echo = 6;
int buzz = 5;
long duration ;
int distance;


 
void setup() {
  // put your setup code here, to run once:
  pinMode(trig,OUTPUT);
  pinMode(echo, INPUT);
  pinMode(buzz, OUTPUT);
  Serial.begin(9600);
  

  
  
}
void loop() {
  digitalWrite(trig,HIGH);
  delay(10);
  digitalWrite(trig,LOW);
  duration = pulseIn(echo,HIGH);
  distance = duration*0.017;
  Serial.print("distance = ");
  Serial.println(distance);
  if(distance<=20){
    digitalWrite(buzz , HIGH);
    
  }
  else{
    digitalWrite(buzz ,LOW);
  }
}
  // put your main code here, to run repeatedly:
  
  

Credits

Abdulrahman mahmoud
2 projects • 0 followers
hi my name is abdulrahman or you can also say abdoz .i have learned python | Arduino | C++ . Also , iam still more thing about programming.

Comments