Akshay Joseph
Published © GPL3+

Interface Ultrasonic sensor with Arduino Uno

In this article we are going to measure the distance using Arduino Uno and HC-SR04 Ultrasonic sensor

BeginnerProtip28,196
Interface Ultrasonic sensor with Arduino Uno

Things used in this project

Story

Read more

Schematics

Interface Ultrasonic sensor with Arduino Uno

Code

Interface Ultrasonic sensor with Arduino Uno

Arduino
//sketch created by Akshay Joseph
//follow me on Instagram five_volt_player

#define echoPin 2
#define trigPin 3

long duration;
int distance;
void setup(){
  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
 }
void loop(){
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  
 duration=pulseIn(echoPin,HIGH);
  distance=(duration*0.034/2);
  Serial.print("Distance : ");
  Serial.print(distance);
  Serial.println(" cm ");
  delay(1000);
               
}

Credits

Akshay Joseph

Akshay Joseph

25 projects • 156 followers
B.Sc. Electronics Student at Govt. College Tanur

Comments